https://bugs.llvm.org/show_bug.cgi?id=51968

            Bug ID: 51968
           Summary: Regression with GEPs after ""[InstCombine] Negator:
                    -(X << C) --> X * (-1 << C)""
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

llvm/test/Transforms/InstCombine/icmp.llm see test24

define i1 @test24_neg_offs(i32* %p, i64 %offs) {
  %p1 = getelementptr inbounds i32, i32* %p, i64 %offs
  %conv1 = ptrtoint i32* %p to i64
  %conv2 = ptrtoint i32* %p1 to i64
  %delta = sub i64 %conv1, %conv2
  %cmp = icmp eq i64 %delta, 8
  ret i1 %cmp
}

After that commit, LLVM produces: 
define i1 @test24_neg_offs(i32* nocapture readnone %p, i64 %offs)
local_unnamed_addr #0 {
  %p1.idx.neg = mul i64 %offs, -4
  %cmp = icmp eq i64 %p1.idx.neg, 8
  ret i1 %cmp
}

instead of:
define i1 @mulnsw(i64 %offs) local_unnamed_addr #0 {
  %cmp = icmp eq i64 %offs, -2
  ret i1 %cmp
}


And there is nothing we can do that form to simplify it (missing nsw).


But.. we can add nsw on mul and everything will work fine.


define i1 @src(* %p, i64 %offs) {
%0:
  %p1 = gep inbounds * %p, 4 x i64 %offs
  %conv1 = ptrtoint * %p to i64
  %conv2 = ptrtoint * %p1 to i64
  %delta = sub i64 %conv1, %conv2
  %cmp = icmp eq i64 %delta, 8
  ret i1 %cmp
}
=>
define i1 @tgt(* nocapture noread nowrite %p, i64 %offs) {
%0:
  %p1.idx.neg = mul nsw i64 %offs, -4
  %cmp = icmp eq i64 %p1.idx.neg, 8
  ret i1 %cmp
}
Transformation seems to be correct!


And then LLVM can optimize:
define i1 @mulnsw(i64 %offs) local_unnamed_addr #0 {
  %p1.idx.neg = mul nsw i64 %offs, -4
  %cmp = icmp eq i64 %p1.idx.neg, 8
  ret i1 %cmp
}

To:
define i1 @mulnsw(i64 %offs) local_unnamed_addr #0 {
  %cmp = icmp eq i64 %offs, -2
  ret i1 %cmp
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to