Datasets:

Modalities:
Text
Formats:
json
Size:
< 1K
Tags:
code
DOI:
Libraries:
Datasets
pandas
License:
dtcxzyw commited on
Commit
db22c47
·
1 Parent(s): 8a23f90
examples/baseline.py CHANGED
@@ -22,6 +22,7 @@ sys.path.append(os.path.join(os.path.dirname(os.environ["LAB_DATASET_DIR"]), "sc
22
  import llvm_helper
23
  from lab_env import Environment as Env
24
  from openai import OpenAI
 
25
 
26
  token = os.environ["LAB_LLM_TOKEN"]
27
  url = os.environ.get("LAB_LLM_URL", "https://api.deepseek.com")
@@ -29,10 +30,157 @@ model = os.environ.get("LAB_LLM_MODEL", "deepseek-reasoner")
29
  basemodel_cutoff = os.environ.get("LAB_LLM_BASEMODEL_CUTOFF", "2023-12-31Z")
30
  client = OpenAI(api_key=token, base_url=url)
31
  temperature = 0.0
32
- max_input_tokens = 65536
 
 
 
33
  fix_dir = os.environ["LAB_FIX_DIR"]
34
  os.makedirs(fix_dir, exist_ok=True)
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  def estimate_input_tokens(messages):
38
  return sum(len(chat["content"]) for chat in messages) * 0.3
@@ -47,33 +195,61 @@ def append_message(messages, full_messages, message, dump=True):
47
  full_messages.append(message)
48
 
49
 
50
- def chat(messages, full_messages):
51
  reasoning_content = ""
52
  content = ""
53
  try:
54
- response = client.chat.completions.create(
55
- model=model,
56
- messages=messages,
57
- stream=True,
58
- timeout=300,
59
- temperature=temperature,
60
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  print("assistant:")
63
- thinking = False
64
- for chunk in response:
65
- if (
66
- hasattr(chunk.choices[0].delta, "reasoning_content")
67
- and chunk.choices[0].delta.reasoning_content
68
- ):
69
- if not thinking:
70
- print("Thinking: ", end="")
71
- thinking = True
72
- val = chunk.choices[0].delta.reasoning_content
73
- print(val, end="")
74
- reasoning_content += val
75
- elif chunk.choices[0].delta.content:
76
- content += chunk.choices[0].delta.content
77
  print("Answer:")
78
  print(content)
79
  except json.JSONDecodeError as e:
@@ -98,6 +274,7 @@ def get_system_prompt() -> str:
98
  """You are an LLVM maintainer.
99
  You are fixing a middle-end bug in the LLVM project."""
100
  + format_requirement
 
101
  )
102
 
103
 
@@ -158,6 +335,8 @@ def get_issue_desc(env: Env) -> str:
158
 
159
  def normalize_feedback(log) -> str:
160
  if not isinstance(log, list):
 
 
161
  return str(log)
162
  return json.dumps(llvm_helper.get_first_failed_test(log), indent=2)
163
 
@@ -166,7 +345,7 @@ def issue_fixing_iter(
166
  env: Env, file, src, messages, full_messages, context_requirement
167
  ):
168
  env.reset()
169
- tgt = chat(messages, full_messages)
170
  modify_inplace(file, src, tgt)
171
  res, log = env.check_full()
172
  if res:
 
22
  import llvm_helper
23
  from lab_env import Environment as Env
24
  from openai import OpenAI
25
+ from openai import NOT_GIVEN
26
 
27
  token = os.environ["LAB_LLM_TOKEN"]
28
  url = os.environ.get("LAB_LLM_URL", "https://api.deepseek.com")
 
30
  basemodel_cutoff = os.environ.get("LAB_LLM_BASEMODEL_CUTOFF", "2023-12-31Z")
31
  client = OpenAI(api_key=token, base_url=url)
32
  temperature = 0.0
33
+ max_input_tokens = int(os.environ.get("LAB_LLM_CONTEXT_WINDOW_SIZE", 65536))
34
+ # Seems not working, sad :(
35
+ enable_tooling = os.environ.get("LAB_LLM_ENABLE_TOOLING", "OFF") == "ON"
36
+ max_log_size = int(os.environ.get("LAB_LLM_MAX_LOG_SIZE", 1000000000))
37
  fix_dir = os.environ["LAB_FIX_DIR"]
38
  os.makedirs(fix_dir, exist_ok=True)
39
 
40
+ tools = []
41
+ tool_get_source_prompt = "If you need to view the source code, please call the `get_source` function. It is very helpful to address compilation errors by inspecting the latest LLVM API."
42
+ tool_get_source_desc = {
43
+ "type": "function",
44
+ "function": {
45
+ "name": "get_source",
46
+ "description": "Get the first 10 lines of the source code starting from the specified line number.",
47
+ "parameters": {
48
+ "type": "object",
49
+ "properties": {
50
+ "file": {
51
+ "type": "string",
52
+ "description": "Relative path to the source file. Must start with 'llvm/'",
53
+ },
54
+ "lineno": {
55
+ "type": "number",
56
+ "description": "The line number to start from. The first line is 1.",
57
+ },
58
+ },
59
+ "required": ["file", "lineno"],
60
+ },
61
+ },
62
+ }
63
+
64
+
65
+ def tool_get_source(env, args):
66
+ file = args["file"]
67
+ if not file.startswith("llvm/") or file.contains(".."):
68
+ return "Invalid file path"
69
+ lineno = int(args["lineno"])
70
+ path = os.path.join(llvm_helper.llvm_dir, file)
71
+ env.reset()
72
+ env.use_knowledge(f"source file: {file}:{lineno}", env.knowledge_cutoff)
73
+ with open(path) as f:
74
+ source = f.readlines()
75
+ return "```cpp\n" + "".join(source[lineno - 1 : lineno + 9]) + "```\n"
76
+
77
+
78
+ tools.append((tool_get_source_prompt, tool_get_source_desc, tool_get_source))
79
+
80
+ tool_get_instruction_docs_prompt = "If you need the definition of an LLVM instruction or an intrinsic, please call the `get_instruction_docs` function. It is useful to understand new poison-generating flags."
81
+ tool_get_instruction_docs_desc = {
82
+ "type": "function",
83
+ "function": {
84
+ "name": "get_instruction_docs",
85
+ "description": "Get the documentation of an LLVM instruction or an intrinsic.",
86
+ "parameters": {
87
+ "type": "object",
88
+ "properties": {
89
+ "inst": {
90
+ "type": "string",
91
+ "description": "The name of the instruction or intrinsic (e.g., 'add', 'llvm.ctpop'). Do not include the suffix for type mangling.",
92
+ }
93
+ },
94
+ "required": ["inst"],
95
+ },
96
+ },
97
+ }
98
+
99
+
100
+ def tool_get_instruction_docs(env, args):
101
+ inst = args["inst"]
102
+ return env.get_langref_desc([inst])[inst]
103
+
104
+
105
+ tools.append(
106
+ (
107
+ tool_get_instruction_docs_prompt,
108
+ tool_get_instruction_docs_desc,
109
+ tool_get_instruction_docs,
110
+ )
111
+ )
112
+
113
+
114
+ tool_check_refinement_prompt = "If you want to check if an optimization is correct, please call the `check_refinement` function. If the optimization is incorrect, the function will provide a counterexample."
115
+ tool_check_refinement_desc = {
116
+ "type": "function",
117
+ "function": {
118
+ "name": "check_refinement",
119
+ "description": "Check if an optimization is correct. If the optimization is incorrect, the function will provide a counterexample.",
120
+ "parameters": {
121
+ "type": "object",
122
+ "properties": {
123
+ "src": {
124
+ "type": "string",
125
+ "description": "The original LLVM function.",
126
+ },
127
+ "tgt": {
128
+ "type": "string",
129
+ "description": "The optimized LLVM function. The name of target function should be the same as the original function.",
130
+ },
131
+ },
132
+ "required": ["src", "tgt"],
133
+ },
134
+ },
135
+ }
136
+
137
+
138
+ def tool_check_refinement(env, args):
139
+ src = args["src"]
140
+ tgt = args["tgt"]
141
+ env.use_knowledge(f"alive2", env.knowledge_cutoff)
142
+ if "ptr" in src and "target datalayout" not in src:
143
+ src = f'target datalayout = "p:8:8:8"\n{src}'
144
+ if "ptr" in tgt and "target datalayout" not in tgt:
145
+ tgt = f'target datalayout = "p:8:8:8"\n{tgt}'
146
+
147
+ res, log = llvm_helper.alive2_check(src, tgt, "-src-unroll=8 -tgt-unroll=8")
148
+ if res:
149
+ return "The optimization is correct."
150
+ return log
151
+
152
+
153
+ tools.append(
154
+ (tool_check_refinement_prompt, tool_check_refinement_desc, tool_check_refinement)
155
+ )
156
+
157
+
158
+ def get_tooling_prompt():
159
+ if not enable_tooling:
160
+ return ""
161
+ prompt = "You are allowed to use the following functions when fixing this bug:\n"
162
+ for x in tools:
163
+ prompt += x[0] + "\n"
164
+ return prompt
165
+
166
+
167
+ def get_available_tools():
168
+ if not enable_tooling:
169
+ return NOT_GIVEN
170
+ return [x[1] for x in tools]
171
+
172
+
173
+ def dispatch_tool_call(env, name, args):
174
+ assert enable_tooling
175
+
176
+ try:
177
+ args = json.loads(args)
178
+ for tool in tools:
179
+ if tool[1]["function"]["name"] == name:
180
+ return tool[2](env, args)
181
+ except Exception as e:
182
+ return str(e)
183
+
184
 
185
  def estimate_input_tokens(messages):
186
  return sum(len(chat["content"]) for chat in messages) * 0.3
 
195
  full_messages.append(message)
196
 
197
 
198
+ def chat(env, messages, full_messages):
199
  reasoning_content = ""
200
  content = ""
201
  try:
202
+ while True:
203
+ response = (
204
+ client.chat.completions.create(
205
+ model=model,
206
+ messages=messages,
207
+ timeout=300,
208
+ temperature=temperature,
209
+ tools=get_available_tools(),
210
+ )
211
+ .choices[0]
212
+ .message
213
+ )
214
+ if response.tool_calls is None or len(response.tool_calls) == 0:
215
+ break
216
+
217
+ if hasattr(response, "reasoning_content"):
218
+ reasoning_content += response.reasoning_content
219
+ print("Thinking:")
220
+ print(response.reasoning_content)
221
+
222
+ messages.append(response)
223
+
224
+ for tool_call in response.tool_calls:
225
+ name = tool_call.function.name
226
+ args = tool_call.function.arguments
227
+ res = dispatch_tool_call(env, name, args)
228
+ print(f"Call tool {name} with")
229
+ print(args)
230
+ print("Result: ", res)
231
+ full_messages.append(
232
+ {
233
+ "role": "assistant - funccall",
234
+ "tool_name": name,
235
+ "tool_args": args,
236
+ "tool_res": res,
237
+ }
238
+ )
239
+ messages.append(
240
+ {
241
+ "role": "tool",
242
+ "tool_call_id": tool_call.id,
243
+ "content": str(res),
244
+ }
245
+ )
246
 
247
  print("assistant:")
248
+ if hasattr(response, "reasoning_content"):
249
+ reasoning_content += response.reasoning_content
250
+ print("Thinking:")
251
+ print(response.reasoning_content)
252
+ content = response.content
 
 
 
 
 
 
 
 
 
253
  print("Answer:")
254
  print(content)
255
  except json.JSONDecodeError as e:
 
274
  """You are an LLVM maintainer.
275
  You are fixing a middle-end bug in the LLVM project."""
276
  + format_requirement
277
+ + get_tooling_prompt()
278
  )
279
 
280
 
 
335
 
336
  def normalize_feedback(log) -> str:
337
  if not isinstance(log, list):
338
+ if len(log) > max_log_size:
339
+ return log[:max_log_size] + "\n<Truncated>..."
340
  return str(log)
341
  return json.dumps(llvm_helper.get_first_failed_test(log), indent=2)
342
 
 
345
  env: Env, file, src, messages, full_messages, context_requirement
346
  ):
347
  env.reset()
348
+ tgt = chat(env, messages, full_messages)
349
  modify_inplace(file, src, tgt)
350
  res, log = env.check_full()
351
  if res:
examples/fixes/118798.json DELETED
@@ -1,74 +0,0 @@
1
- {
2
- "wall_time": 454.34026074409485,
3
- "knowledge": [
4
- [
5
- "base_model",
6
- "2023-12-31+0000"
7
- ],
8
- [
9
- "hint:bug_functions",
10
- "2024-12-05+0000"
11
- ],
12
- [
13
- "hint:components",
14
- "2024-12-05+0000"
15
- ],
16
- [
17
- "hint:issue",
18
- "2024-12-05+0000"
19
- ],
20
- [
21
- "hint:line_level_bug_locations",
22
- "2024-12-05+0000"
23
- ]
24
- ],
25
- "build_count": 5,
26
- "build_failure_count": 1,
27
- "fast_check_count": 1,
28
- "full_check_count": 4,
29
- "fast_check_pass": false,
30
- "full_check_pass": false,
31
- "patch": "diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp\nindex 10c3ccdb2243..a4d6b1268d50 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp\n@@ -409,8 +409,7 @@ Instruction *InstCombinerImpl::commonShiftTransforms(BinaryOperator &I) {\n Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);\n assert(Op0->getType() == Op1->getType());\n Type *Ty = I.getType();\n-\n- // If the shift amount is a one-use `sext`, we can demote it to `zext`.\n+// If the shift amount is a one-use `sext`, we can demote it to `zext`.\n Value *Y;\n if (match(Op1, m_OneUse(m_SExt(m_Value(Y))))) {\n Value *NewExt = Builder.CreateZExt(Y, Ty, Op1->getName());\n@@ -431,9 +430,13 @@ Instruction *InstCombinerImpl::commonShiftTransforms(BinaryOperator &I) {\n if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))\n return Res;\n \n- if (auto *NewShift = cast_or_null<Instruction>(\n- reassociateShiftAmtsOfTwoSameDirectionShifts(&I, SQ)))\n- return NewShift;\n+ // Don't reassociate shifts if the shift amount is a pointer type or if the\n+ // shift amount is not a constant.\n+ if (!Op1->getType()->isPointerTy() && isa<Constant>(Op1) && isa<Constant>(Op0)) {\n+ if (auto *NewShift = cast_or_null<Instruction>(\n+ reassociateShiftAmtsOfTwoSameDirectionShifts(&I, SQ)))\n+ return NewShift;\n+ }\n \n // Pre-shift a constant shifted by a variable amount with constant offset:\n // C shift (A add nuw C1) --> (C shift C1) shift A\n@@ -446,6 +449,11 @@ Instruction *InstCombinerImpl::commonShiftTransforms(BinaryOperator &I) {\n if (I.getOpcode() == Instruction::Shl) {\n NewShiftOp->setHasNoSignedWrap(I.hasNoSignedWrap());\n NewShiftOp->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());\n+ }\n+ return NewShiftOp;\n+ }\n+\n+ return nullptr;\n } else {\n NewShiftOp->setIsExact(I.isExact());\n }\n",
32
- "log": [
33
- {
34
- "role": "system",
35
- "content": "You are an LLVM maintainer.\nYou are fixing a middle-end bug in the LLVM project.\nPlease answer with the code directly. Do not include any additional information.\n"
36
- },
37
- {
38
- "role": "user",
39
- "content": "This is a hang bug in InstCombine.\nIssue title: [InstCombine] Infinite loop when combining two `shl` instructions\nIssue body: The following sample triggers an infinite loop in instcombine:\n\n```\n@c = external constant i8\n@c2 = external constant i8\n\ndefine i16 @testfunc() {\nentry:\n %0 = shl i64 1, ptrtoint (ptr @c2 to i64)\n %1 = shl i64 %0, ptrtoint (ptr @c to i64)\n %2 = inttoptr i64 %1 to ptr\n %3 = load i16, ptr %2, align 1\n ret i16 %3\n}\n```\n\nhttps://godbolt.org/z/WP6YvGjPq\n\nDetailed information:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/shl-twice-constant.ll\",\n \"args\": \"opt < %s -passes=instcombine -S\",\n \"name\": \"testfunc\",\n \"body\": \"@c = external constant i8\\n@c2 = external constant i8\\n\\ndefine i64 @testfunc() {\\n %shl1 = shl i64 1, ptrtoint (ptr @c2 to i64)\\n %shl2 = shl i64 %shl1, ptrtoint (ptr @c to i64)\\n ret i64 %shl2\\n}\\n\",\n \"result\": false,\n \"log\": \"Command '['/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt', '-', '-passes=instcombine', '-S']' timed out after 10.0 seconds\\n\\n\"\n}\nPlease modify the following code in llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:InstCombinerImpl::commonShiftTransforms to fix the bug:\n```\n\n // If the shift amount is a one-use `sext`, we can demote it to `zext`.\n Value *Y;\n if (match(Op1, m_OneUse(m_SExt(m_Value(Y))))) {\n Value *NewExt = Builder.CreateZExt(Y, Ty, Op1->getName());\n return BinaryOperator::Create(I.getOpcode(), Op0, NewExt);\n }\n\n // See if we can fold away this shift.\n if (SimplifyDemandedInstructionBits(I))\n return &I;\n\n // Try to fold constant and into select arguments.\n if (isa<Constant>(Op0))\n if (SelectInst *SI = dyn_cast<SelectInst>(Op1))\n if (Instruction *R = FoldOpIntoSelect(I, SI))\n return R;\n\n if (Constant *CUI = dyn_cast<Constant>(Op1))\n if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))\n return Res;\n\n if (auto *NewShift = cast_or_null<Instruction>(\n reassociateShiftAmtsOfTwoSameDirectionShifts(&I, SQ)))\n return NewShift;\n\n // Pre-shift a constant shifted by a variable amount with constant offset:\n // C shift (A add nuw C1) --> (C shift C1) shift A\n Value *A;\n Constant *C, *C1;\n if (match(Op0, m_Constant(C)) &&\n match(Op1, m_NUWAddLike(m_Value(A), m_Constant(C1)))) {\n Value *NewC = Builder.CreateBinOp(I.getOpcode(), C, C1);\n BinaryOperator *NewShiftOp = BinaryOperator::Create(I.getOpcode(), NewC, A);\n if (I.getOpcode() == Instruction::Shl) {\n NewShiftOp->setHasNoSignedWrap(I.hasNoSignedWrap());\n NewShiftOp->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());\n```\n"
40
- },
41
- {
42
- "role": "assistant",
43
- "content": "```cpp\n // If the shift amount is a one-use `sext`, we can demote it to `zext`.\n Value *Y;\n if (match(Op1, m_OneUse(m_SExt(m_Value(Y))))) {\n Value *NewExt = Builder.CreateZExt(Y, Ty, Op1->getName());\n return BinaryOperator::Create(I.getOpcode(), Op0, NewExt);\n }\n\n // See if we can fold away this shift.\n if (SimplifyDemandedInstructionBits(I))\n return &I;\n\n // Try to fold constant and into select arguments.\n if (isa<Constant>(Op0))\n if (SelectInst *SI = dyn_cast<SelectInst>(Op1))\n if (Instruction *R = FoldOpIntoSelect(I, SI))\n return R;\n\n if (Constant *CUI = dyn_cast<Constant>(Op1))\n if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))\n return Res;\n\n // Don't reassociate shifts if the shift amount is a pointer type.\n if (!Op1->getType()->isPointerTy()) {\n if (auto *NewShift = cast_or_null<Instruction>(\n reassociateShiftAmtsOfTwoSameDirectionShifts(&I, SQ)))\n return NewShift;\n }\n\n // Pre-shift a constant shifted by a variable amount with constant offset:\n // C shift (A add nuw C1) --> (C shift C1) shift A\n Value *A;\n Constant *C, *C1;\n if (match(Op0, m_Constant(C)) &&\n match(Op1, m_NUWAddLike(m_Value(A), m_Constant(C1)))) {\n Value *NewC = Builder.CreateBinOp(I.getOpcode(), C, C1);\n BinaryOperator *NewShiftOp = BinaryOperator::Create(I.getOpcode(), NewC, A);\n if (I.getOpcode() == Instruction::Shl) {\n NewShiftOp->setHasNoSignedWrap(I.hasNoSignedWrap());\n NewShiftOp->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());\n```"
44
- },
45
- {
46
- "role": "user",
47
- "content": "Feedback:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/shl-twice-constant.ll\",\n \"args\": \"opt < %s -passes=instcombine -S\",\n \"name\": \"testfunc\",\n \"body\": \"@c = external constant i8\\n@c2 = external constant i8\\n\\ndefine i64 @testfunc() {\\n %shl1 = shl i64 1, ptrtoint (ptr @c2 to i64)\\n %shl2 = shl i64 %shl1, ptrtoint (ptr @c to i64)\\n ret i64 %shl2\\n}\\n\",\n \"result\": false,\n \"log\": \"Command '['/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt', '-', '-passes=instcombine', '-S']' timed out after 10.0 seconds\\n\\n\"\n}\nPlease adjust code according to the feedback. Do not include any additional information.\n"
48
- },
49
- {
50
- "role": "assistant",
51
- "content": "```cpp\n // If the shift amount is a one-use `sext`, we can demote it to `zext`.\n Value *Y;\n if (match(Op1, m_OneUse(m_SExt(m_Value(Y))))) {\n Value *NewExt = Builder.CreateZExt(Y, Ty, Op1->getName());\n return BinaryOperator::Create(I.getOpcode(), Op0, NewExt);\n }\n\n // See if we can fold away this shift.\n if (SimplifyDemandedInstructionBits(I))\n return &I;\n\n // Try to fold constant and into select arguments.\n if (isa<Constant>(Op0))\n if (SelectInst *SI = dyn_cast<SelectInst>(Op1))\n if (Instruction *R = FoldOpIntoSelect(I, SI))\n return R;\n\n if (Constant *CUI = dyn_cast<Constant>(Op1))\n if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))\n return Res;\n\n // Don't reassociate shifts if the shift amount is a pointer type or if the\n // shift amount is not a constant.\n if (!Op1->getType()->isPointerTy() && isa<Constant>(Op1)) {\n if (auto *NewShift = cast_or_null<Instruction>(\n reassociateShiftAmtsOfTwoSameDirectionShifts(&I, SQ)))\n return NewShift;\n }\n\n // Pre-shift a constant shifted by a variable amount with constant offset:\n // C shift (A add nuw C1) --> (C shift C1) shift A\n Value *A;\n Constant *C, *C1;\n if (match(Op0, m_Constant(C)) &&\n match(Op1, m_NUWAddLike(m_Value(A), m_Constant(C1)))) {\n Value *NewC = Builder.CreateBinOp(I.getOpcode(), C, C1);\n BinaryOperator *NewShiftOp = BinaryOperator::Create(I.getOpcode(), NewC, A);\n if (I.getOpcode() == Instruction::Shl) {\n NewShiftOp->setHasNoSignedWrap(I.hasNoSignedWrap());\n NewShiftOp->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());\n```"
52
- },
53
- {
54
- "role": "user",
55
- "content": "Feedback:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/shl-twice-constant.ll\",\n \"args\": \"opt < %s -passes=instcombine -S\",\n \"name\": \"testfunc\",\n \"body\": \"@c = external constant i8\\n@c2 = external constant i8\\n\\ndefine i64 @testfunc() {\\n %shl1 = shl i64 1, ptrtoint (ptr @c2 to i64)\\n %shl2 = shl i64 %shl1, ptrtoint (ptr @c to i64)\\n ret i64 %shl2\\n}\\n\",\n \"result\": false,\n \"log\": \"Command '['/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt', '-', '-passes=instcombine', '-S']' timed out after 10.0 seconds\\n\\n\"\n}\nPlease adjust code according to the feedback. Do not include any additional information.\n"
56
- },
57
- {
58
- "role": "assistant",
59
- "content": "```cpp\n // If the shift amount is a one-use `sext`, we can demote it to `zext`.\n Value *Y;\n if (match(Op1, m_OneUse(m_SExt(m_Value(Y))))) {\n Value *NewExt = Builder.CreateZExt(Y, Ty, Op1->getName());\n return BinaryOperator::Create(I.getOpcode(), Op0, NewExt);\n }\n\n // See if we can fold away this shift.\n if (SimplifyDemandedInstructionBits(I))\n return &I;\n\n // Try to fold constant and into select arguments.\n if (isa<Constant>(Op0))\n if (SelectInst *SI = dyn_cast<SelectInst>(Op1))\n if (Instruction *R = FoldOpIntoSelect(I, SI))\n return R;\n\n if (Constant *CUI = dyn_cast<Constant>(Op1))\n if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))\n return Res;\n\n // Don't reassociate shifts if the shift amount is a pointer type or if the\n // shift amount is not a constant.\n if (!Op1->getType()->isPointerTy() && isa<Constant>(Op1) && isa<Constant>(Op0)) {\n if (auto *NewShift = cast_or_null<Instruction>(\n reassociateShiftAmtsOfTwoSameDirectionShifts(&I, SQ)))\n return NewShift;\n }\n\n // Pre-shift a constant shifted by a variable amount with constant offset:\n // C shift (A add nuw C1) --> (C shift C1) shift A\n Value *A;\n Constant *C, *C1;\n if (match(Op0, m_Constant(C)) &&\n match(Op1, m_NUWAddLike(m_Value(A), m_Constant(C1)))) {\n Value *NewC = Builder.CreateBinOp(I.getOpcode(), C, C1);\n BinaryOperator *NewShiftOp = BinaryOperator::Create(I.getOpcode(), NewC, A);\n if (I.getOpcode() == Instruction::Shl) {\n NewShiftOp->setHasNoSignedWrap(I.hasNoSignedWrap());\n NewShiftOp->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());\n```"
60
- },
61
- {
62
- "role": "user",
63
- "content": "Feedback:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/shl-twice-constant.ll\",\n \"args\": \"opt < %s -passes=instcombine -S\",\n \"name\": \"testfunc\",\n \"body\": \"@c = external constant i8\\n@c2 = external constant i8\\n\\ndefine i64 @testfunc() {\\n %shl1 = shl i64 1, ptrtoint (ptr @c2 to i64)\\n %shl2 = shl i64 %shl1, ptrtoint (ptr @c to i64)\\n ret i64 %shl2\\n}\\n\",\n \"result\": false,\n \"log\": \"Command '['/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt', '-', '-passes=instcombine', '-S']' timed out after 10.0 seconds\\n\\n\"\n}\nPlease adjust code according to the feedback. Do not include any additional information.\n"
64
- },
65
- {
66
- "role": "assistant",
67
- "content": "```cpp\n // If the shift amount is a one-use `sext`, we can demote it to `zext`.\n Value *Y;\n if (match(Op1, m_OneUse(m_SExt(m_Value(Y))))) {\n Value *NewExt = Builder.CreateZExt(Y, Ty, Op1->getName());\n return BinaryOperator::Create(I.getOpcode(), Op0, NewExt);\n }\n\n // See if we can fold away this shift.\n if (SimplifyDemandedInstructionBits(I))\n return &I;\n\n // Try to fold constant and into select arguments.\n if (isa<Constant>(Op0))\n if (SelectInst *SI = dyn_cast<SelectInst>(Op1))\n if (Instruction *R = FoldOpIntoSelect(I, SI))\n return R;\n\n if (Constant *CUI = dyn_cast<Constant>(Op1))\n if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))\n return Res;\n\n // Don't reassociate shifts if the shift amount is a pointer type or if the\n // shift amount is not a constant.\n if (!Op1->getType()->isPointerTy() && isa<Constant>(Op1) && isa<Constant>(Op0)) {\n if (auto *NewShift = cast_or_null<Instruction>(\n reassociateShiftAmtsOfTwoSameDirectionShifts(&I, SQ)))\n return NewShift;\n }\n\n // Pre-shift a constant shifted by a variable amount with constant offset:\n // C shift (A add nuw C1) --> (C shift C1) shift A\n Value *A;\n Constant *C, *C1;\n if (match(Op0, m_Constant(C)) &&\n match(Op1, m_NUWAddLike(m_Value(A), m_Constant(C1)))) {\n Value *NewC = Builder.CreateBinOp(I.getOpcode(), C, C1);\n BinaryOperator *NewShiftOp = BinaryOperator::Create(I.getOpcode(), NewC, A);\n if (I.getOpcode() == Instruction::Shl) {\n NewShiftOp->setHasNoSignedWrap(I.hasNoSignedWrap());\n NewShiftOp->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());\n }\n return NewShiftOp;\n }\n\n return nullptr;\n```"
68
- },
69
- {
70
- "role": "user",
71
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (6.0s)\n-- Generating done (3.1s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/85] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/85] Linking CXX executable bin/llvm-config\n[3/85] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineShifts.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineShifts.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineShifts.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineShifts.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineShifts.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:457:7: error: expected unqualified-id before \u2018else\u2019\n 457 | } else {\n | ^~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:460:5: error: expected unqualified-id before \u2018return\u2019\n 460 | return NewShiftOp;\n | ^~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:461:3: error: expected declaration before \u2018}\u2019 token\n 461 | }\n | ^\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:463:23: error: \u2018Ty\u2019 was not declared in this scope\n 463 | unsigned BitWidth = Ty->getScalarSizeInBits();\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:471:3: error: expected unqualified-id before \u2018if\u2019\n 471 | if (match(Op0, m_APInt(AC)) && match(Op1, m_Add(m_Value(A), m_APInt(AddC))) &&\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:507:3: error: expected unqualified-id before \u2018if\u2019\n 507 | if (Op1->hasOneUse() && match(Op1, m_SRem(m_Value(A), m_Constant(C))) &&\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:516:3: error: expected unqualified-id before \u2018if\u2019\n 516 | if (Instruction *Logic = foldShiftOfShiftedBinOp(I, Builder))\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:519:3: error: expected unqualified-id before \u2018if\u2019\n 519 | if (match(Op1, m_Or(m_Value(), m_SpecificInt(BitWidth - 1))))\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:523:3: error: expected unqualified-id before \u2018if\u2019\n 523 | if ((I.getOpcode() == Instruction::LShr ||\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:537:3: error: expected unqualified-id before \u2018return\u2019\n 537 | return nullptr;\n | ^~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp:538:1: error: expected declaration before \u2018}\u2019 token\n 538 | }\n | ^\nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback. Do not include any additional information.\n"
72
- }
73
- ]
74
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
examples/fixes/119063.json DELETED
@@ -1,74 +0,0 @@
1
- {
2
- "wall_time": 55.75930976867676,
3
- "knowledge": [
4
- [
5
- "base_model",
6
- "2023-12-31+0000"
7
- ],
8
- [
9
- "hint:bug_functions",
10
- "2024-12-07+0000"
11
- ],
12
- [
13
- "hint:components",
14
- "2024-12-07+0000"
15
- ],
16
- [
17
- "hint:issue",
18
- "2024-12-07+0000"
19
- ],
20
- [
21
- "hint:line_level_bug_locations",
22
- "2024-12-07+0000"
23
- ]
24
- ],
25
- "build_count": 5,
26
- "build_failure_count": 1,
27
- "fast_check_count": 1,
28
- "full_check_count": 4,
29
- "fast_check_pass": false,
30
- "full_check_pass": false,
31
- "patch": "diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\nindex b694fde30927..b24607afa3c7 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n@@ -3604,7 +3604,7 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(\n break;\n case Instruction::Or: {\n const APInt *BOC;\n- if (match(BOp1, m_APInt(BOC)) && BO->hasOneUse() && RHS->isAllOnesValue()) {\n+if (match(BOp1, m_APInt(BOC)) && BO->hasOneUse() && RHS->isAllOnesValue()) {\n // Comparing if all bits outside of a constant mask are set?\n // Replace (X | C) == -1 with (X & ~C) == ~C.\n // This removes the -1 constant.\n@@ -3630,6 +3630,9 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(\n : (match(FV, m_Zero()) && isKnownNonZero(TV, Q))) {\n Value *Cmp = Builder.CreateICmp(\n Pred, Other, Constant::getNullValue(Other->getType()));\n+ if (Cmp->getType() != Cond->getType() && \n+ Cond->getType()->isIntegerTy(1) && Cmp->getType()->isIntegerTy(1))\n+ Cond = Builder.CreateIntCast(Cond, Cmp->getType(), /*isSigned*/false);\n return BinaryOperator::Create(\n Pred == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or, Cmp,\n Cond);\n",
32
- "log": [
33
- {
34
- "role": "system",
35
- "content": "You are an LLVM maintainer.\nYou are fixing a middle-end bug in the LLVM project.\nPlease answer with the code directly. Do not include any additional information.\n"
36
- },
37
- {
38
- "role": "user",
39
- "content": "This is a crash bug in InstCombine.\nIssue title: [InstCombine] Assertion `S1->getType() == S2->getType() && \"Cannot create binary operator with two operands of differing type!\"' failed.\nIssue body: This code crashes at O2/3:\n```c\nint a, b;\nstatic int c;\nstatic int *d = &c;\nshort e;\nchar g;\nunsigned short h;\nint *i;\nint j(int k) {\n if (k & a)\n return 1;\n return 0;\n}\nint l(int k) {\n int f = j(k);\n return f;\n}\nvoid n() { int *m[] = {0, &d}; }\nvoid o() {\n for (; g; g++) {\n int *p = &b;\n short *q = &e;\n int r = l(*d + 5);\n *p = 0;\n *q = *i || (unsigned short)(r + 22158 + 36566 + *d - 1641080165) + h;\n }\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/n7GPEKsxb\n\nBisected to https://github.com/llvm/llvm-project/commit/4eb98384099cbd1d901d8ef6a210af95d9c36adf, which was committed by @fhahn \n\nCrash: \n```\nclang: /root/llvm-project/llvm/lib/IR/Instructions.cpp:2642: static llvm::BinaryOperator* llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::InsertPosition): Assertion `S1->getType() == S2->getType() && \"Cannot create binary operator with two operands of differing type!\"' failed.\n```\n\nBacktrace:\n```\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -Wall -Wextra <source>\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"<source>\"\n4.\tRunning pass \"instcombine<max-iterations=1;no-verify-fixpoint>\" on function \"o\"\n #0 0x0000000003c05148 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c05148)\n #1 0x0000000003c02e54 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c02e54)\n #2 0x0000000003b503b8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x00007bfb65442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007bfb654969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x00007bfb65442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007bfb654287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007bfb6542871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007bfb65439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x000000000351a1f3 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x351a1f3)\n#10 0x0000000003523d7c (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3523d7c)\n#11 0x00000000037edc06 llvm::InstCombinerImpl::foldICmpBinOpEqualityWithConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x37edc06)\n#12 0x0000000003810ac9 llvm::InstCombinerImpl::foldICmpInstWithConstant(llvm::ICmpInst&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3810ac9)\n#13 0x0000000003819aad llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3819aad)\n#14 0x0000000003775251 llvm::InstCombinerImpl::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3775251)\n#15 0x0000000003776bc6 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) (.isra.0) InstructionCombining.cpp:0:0\n#16 0x000000000377805c llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x377805c)\n#17 0x0000000003ea39ae llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ea39ae)\n#18 0x00000000035b5920 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35b5920)\n#19 0x00000000010f19ce llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10f19ce)\n#20 0x00000000035b423b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35b423b)\n#21 0x00000000010f105e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10f105e)\n#22 0x00000000035b3c40 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35b3c40)\n#23 0x0000000003eb5912 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#24 0x0000000003eb918d clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3eb918d)\n#25 0x00000000045875de clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45875de)\n#26 0x000000000654152c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x654152c)\n#27 0x00000000045879b8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45879b8)\n#28 0x0000000004842b39 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4842b39)\n#29 0x00000000047c27ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47c27ce)\n#30 0x000000000492db9e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x492db9e)\n#31 0x0000000000cb21bf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcb21bf)\n#32 0x0000000000ca9d5a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#33 0x00000000045cad09 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#34 0x0000000003b50864 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b50864)\n#35 0x00000000045cb2ff clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#36 0x000000000459149d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x459149d)\n#37 0x000000000459258d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x459258d)\n#38 0x0000000004599945 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4599945)\n#39 0x0000000000caf003 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcaf003)\n#40 0x0000000000b82f64 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xb82f64)\n#41 0x00007bfb65429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#42 0x00007bfb65429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#43 0x0000000000ca9805 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xca9805)\n```\nDetailed information:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll\",\n \"args\": \"opt < %s -passes=instcombine -S\",\n \"name\": \"pr119063\",\n \"body\": \"define <4 x i1> @pr119063(<4 x i32> %x, i1 %cond) {\\nentry:\\n %sel = select i1 %cond, <4 x i32> splat (i32 1), <4 x i32> zeroinitializer\\n %or = or <4 x i32> %sel, %x\\n %cmp = icmp ne <4 x i32> %or, zeroinitializer\\n ret <4 x i1> %cmp\\n}\\n\",\n \"result\": false,\n \"log\": \"Command '['/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt', '-', '-passes=instcombine', '-S']' died with <Signals.SIGABRT: 6>.\\n\\nopt: /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/IR/Instructions.cpp:2642: static llvm::BinaryOperator* llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::InsertPosition): Assertion `S1->getType() == S2->getType() && \\\"Cannot create binary operator with two operands of differing type!\\\"' failed.\\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\\nStack dump:\\n0.\\tProgram arguments: /data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt - -passes=instcombine -S\\n1.\\tRunning pass \\\"function(instcombine<max-iterations=1;verify-fixpoint>)\\\" on module \\\"<stdin>\\\"\\n2.\\tRunning pass \\\"instcombine<max-iterations=1;verify-fixpoint>\\\" on function \\\"pr119063\\\"\\n #0 0x00007ffff7eb779c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:727:3\\n #1 0x00007ffff7eb5234 llvm::sys::RunSignalHandlers() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Signals.cpp:105:20\\n #2 0x00007ffff7eb558e SignalHandler(int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1\\n #3 0x00007ffff7b3d090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\\n #4 0x00007ffff7b3d00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\\n #5 0x00007ffff7b1c859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\\n #6 0x00007ffff7b1c729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\\n #7 0x00007ffff7b1c729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\\n #8 0x00007ffff7b2dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\\n #9 0x00007ffff2233fb4 (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x226fb4)\\n#10 0x00007ffff34d3d1f llvm::InstCombinerImpl::foldICmpBinOpEqualityWithConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3633:38\\n#11 0x00007ffff34ea12b llvm::InstCombinerImpl::foldICmpInstWithConstant(llvm::ICmpInst&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3502:7\\n#12 0x00007ffff34f9218 llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:7539:50\\n#13 0x00007ffff3455111 llvm::InstCombinerImpl::run() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5201:36\\n#14 0x00007ffff34560d3 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5519:5\\n#15 0x00007ffff3456a7b llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5581:3\\n#16 0x00007ffff4c7e736 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#17 0x00007ffff22b6dcc llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#18 0x00007ffff725b376 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#19 0x00007ffff22b72f9 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/IR/PassManager.cpp:129:41\\n#20 0x00007ffff725bd36 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#21 0x00007ffff22b5215 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#22 0x00007ffff7fa5e63 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:84:5\\n#23 0x00007ffff7fa5e63 llvm::SmallPtrSetImpl<llvm::AnalysisKey*>::~SmallPtrSetImpl() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:363:7\\n#24 0x00007ffff7fa5e63 llvm::SmallPtrSet<llvm::AnalysisKey*, 2u>::~SmallPtrSet() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:519:7\\n#25 0x00007ffff7fa5e63 llvm::PreservedAnalyses::~PreservedAnalyses() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/Analysis.h:111:7\\n#26 0x00007ffff7fa5e63 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/NewPMDriver.cpp:541:10\\n#27 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_data() const /usr/include/c++/10/bits/basic_string.h:195:28\\n#28 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_is_local() const /usr/include/c++/10/bits/basic_string.h:230:23\\n#29 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_dispose() /usr/include/c++/10/bits/basic_string.h:239:18\\n#30 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/include/c++/10/bits/basic_string.h:671:19\\n#31 0x00007ffff7fb065f optMain /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/optdriver.cpp:710:28\\n#32 0x00007ffff7b1e083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\\n#33 0x000055555555509e _start (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt+0x109e)\\n\"\n}\nPlease modify the following code in llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:InstCombinerImpl::foldICmpBinOpEqualityWithConstant to fix the bug:\n```\n if (match(BOp1, m_APInt(BOC)) && BO->hasOneUse() && RHS->isAllOnesValue()) {\n // Comparing if all bits outside of a constant mask are set?\n // Replace (X | C) == -1 with (X & ~C) == ~C.\n // This removes the -1 constant.\n Constant *NotBOC = ConstantExpr::getNot(cast<Constant>(BOp1));\n Value *And = Builder.CreateAnd(BOp0, NotBOC);\n return new ICmpInst(Pred, And, NotBOC);\n }\n // (icmp eq (or (select cond, 0, NonZero), Other), 0)\n // -> (and cond, (icmp eq Other, 0))\n // (icmp ne (or (select cond, NonZero, 0), Other), 0)\n // -> (or cond, (icmp ne Other, 0))\n Value *Cond, *TV, *FV, *Other, *Sel;\n if (C.isZero() &&\n match(BO,\n m_OneUse(m_c_Or(m_CombineAnd(m_Value(Sel),\n m_Select(m_Value(Cond), m_Value(TV),\n m_Value(FV))),\n m_Value(Other))))) {\n const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);\n // Easy case is if eq/ne matches whether 0 is trueval/falseval.\n if (Pred == ICmpInst::ICMP_EQ\n ? (match(TV, m_Zero()) && isKnownNonZero(FV, Q))\n : (match(FV, m_Zero()) && isKnownNonZero(TV, Q))) {\n Value *Cmp = Builder.CreateICmp(\n Pred, Other, Constant::getNullValue(Other->getType()));\n return BinaryOperator::Create(\n Pred == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or, Cmp,\n Cond);\n }\n // Harder case is if eq/ne matches whether 0 is falseval/trueval. In this\n // case we need to invert the select condition so we need to be careful to\n // avoid creating extra instructions.\n // (icmp ne (or (select cond, 0, NonZero), Other), 0)\n // -> (or (not cond), (icmp ne Other, 0))\n // (icmp eq (or (select cond, NonZero, 0), Other), 0)\n // -> (and (not cond), (icmp eq Other, 0))\n```\n"
40
- },
41
- {
42
- "role": "assistant",
43
- "content": "```cpp\n if (match(BOp1, m_APInt(BOC)) && BO->hasOneUse() && RHS->isAllOnesValue()) {\n // Comparing if all bits outside of a constant mask are set?\n // Replace (X | C) == -1 with (X & ~C) == ~C.\n // This removes the -1 constant.\n Constant *NotBOC = ConstantExpr::getNot(cast<Constant>(BOp1));\n Value *And = Builder.CreateAnd(BOp0, NotBOC);\n return new ICmpInst(Pred, And, NotBOC);\n }\n // (icmp eq (or (select cond, 0, NonZero), Other), 0)\n // -> (and cond, (icmp eq Other, 0))\n // (icmp ne (or (select cond, NonZero, 0), Other), 0)\n // -> (or cond, (icmp ne Other, 0))\n Value *Cond, *TV, *FV, *Other, *Sel;\n if (C.isZero() &&\n match(BO,\n m_OneUse(m_c_Or(m_CombineAnd(m_Value(Sel),\n m_Select(m_Value(Cond), m_Value(TV),\n m_Value(FV))),\n m_Value(Other))))) {\n const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);\n // Easy case is if eq/ne matches whether 0 is trueval/falseval.\n if (Pred == ICmpInst::ICMP_EQ\n ? (match(TV, m_Zero()) && isKnownNonZero(FV, Q))\n : (match(FV, m_Zero()) && isKnownNonZero(TV, Q))) {\n Value *Cmp = Builder.CreateICmp(\n Pred, Other, Constant::getNullValue(Other->getType()));\n if (Cmp->getType() != Cond->getType())\n Cond = Builder.CreateIntCast(Cond, Cmp->getType(), /*isSigned*/false);\n return BinaryOperator::Create(\n Pred == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or, Cmp,\n Cond);\n }\n // Harder case is if eq/ne matches whether 0 is falseval/trueval. In this\n // case we need to invert the select condition so we need to be careful to\n // avoid creating extra instructions.\n // (icmp ne (or (select cond, 0, NonZero), Other), 0)\n // -> (or (not cond), (icmp ne Other, 0))\n // (icmp eq (or (select cond, NonZero, 0), Other), 0)\n // -> (and (not cond), (icmp eq Other, 0))\n```\n\nThe fix adds a type check and cast to ensure the condition and comparison result have matching types before creating the binary operator. This prevents the assertion failure when the types don't match."
44
- },
45
- {
46
- "role": "user",
47
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (5.7s)\n-- Generating done (3.1s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/85] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/85] Linking CXX executable bin/llvm-config\n[3/85] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3646:1: error: stray \u2018`\u2019 in program\n 3646 | ```\n | ^\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3646:2: error: stray \u2018`\u2019 in program\n 3646 | ```\n | ^\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3646:3: error: stray \u2018`\u2019 in program\n 3646 | ```\n | ^\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3648:193: error: missing terminating ' character\n 3648 | The fix adds a type check and cast to ensure the condition and comparison result have matching types before creating the binary operator. This prevents the assertion failure when the types don't match.\n | ^~~~~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp: In member function \u2018llvm::Instruction* llvm::InstCombinerImpl::foldICmpBinOpEqualityWithConstant(llvm::ICmpInst&, llvm::BinaryOperator*, const llvm::APInt&)\u2019:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3648:1: error: \u2018The\u2019 was not declared in this scope\n 3648 | The fix adds a type check and cast to ensure the condition and comparison result have matching types before creating the binary operator. This prevents the assertion failure when the types don't match.\n | ^~~\nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback. Do not include any additional information.\n"
48
- },
49
- {
50
- "role": "assistant",
51
- "content": "```cpp\n if (match(BOp1, m_APInt(BOC)) && BO->hasOneUse() && RHS->isAllOnesValue()) {\n // Comparing if all bits outside of a constant mask are set?\n // Replace (X | C) == -1 with (X & ~C) == ~C.\n // This removes the -1 constant.\n Constant *NotBOC = ConstantExpr::getNot(cast<Constant>(BOp1));\n Value *And = Builder.CreateAnd(BOp0, NotBOC);\n return new ICmpInst(Pred, And, NotBOC);\n }\n // (icmp eq (or (select cond, 0, NonZero), Other), 0)\n // -> (and cond, (icmp eq Other, 0))\n // (icmp ne (or (select cond, NonZero, 0), Other), 0)\n // -> (or cond, (icmp ne Other, 0))\n Value *Cond, *TV, *FV, *Other, *Sel;\n if (C.isZero() &&\n match(BO,\n m_OneUse(m_c_Or(m_CombineAnd(m_Value(Sel),\n m_Select(m_Value(Cond), m_Value(TV),\n m_Value(FV))),\n m_Value(Other))))) {\n const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);\n // Easy case is if eq/ne matches whether 0 is trueval/falseval.\n if (Pred == ICmpInst::ICMP_EQ\n ? (match(TV, m_Zero()) && isKnownNonZero(FV, Q))\n : (match(FV, m_Zero()) && isKnownNonZero(TV, Q))) {\n Value *Cmp = Builder.CreateICmp(\n Pred, Other, Constant::getNullValue(Other->getType()));\n if (Cmp->getType() != Cond->getType())\n Cond = Builder.CreateIntCast(Cond, Cmp->getType(), /*isSigned*/false);\n return BinaryOperator::Create(\n Pred == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or, Cmp,\n Cond);\n }\n // Harder case is if eq/ne matches whether 0 is falseval/trueval. In this\n // case we need to invert the select condition so we need to be careful to\n // avoid creating extra instructions.\n // (icmp ne (or (select cond, 0, NonZero), Other), 0)\n // -> (or (not cond), (icmp ne Other, 0))\n // (icmp eq (or (select cond, NonZero, 0), Other), 0)\n // -> (and (not cond), (icmp eq Other, 0))\n```"
52
- },
53
- {
54
- "role": "user",
55
- "content": "Feedback:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll\",\n \"args\": \"opt < %s -passes=instcombine -S\",\n \"name\": \"pr119063\",\n \"body\": \"define <4 x i1> @pr119063(<4 x i32> %x, i1 %cond) {\\nentry:\\n %sel = select i1 %cond, <4 x i32> splat (i32 1), <4 x i32> zeroinitializer\\n %or = or <4 x i32> %sel, %x\\n %cmp = icmp ne <4 x i32> %or, zeroinitializer\\n ret <4 x i1> %cmp\\n}\\n\",\n \"result\": false,\n \"log\": \"Command '['/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt', '-', '-passes=instcombine', '-S']' died with <Signals.SIGABRT: 6>.\\n\\nopt: /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/IR/Instructions.cpp:2974: static llvm::CastInst* llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, const llvm::Twine&, llvm::InsertPosition): Assertion `castIsValid(op, S, Ty) && \\\"Invalid cast!\\\"' failed.\\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\\nStack dump:\\n0.\\tProgram arguments: /data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt - -passes=instcombine -S\\n1.\\tRunning pass \\\"function(instcombine<max-iterations=1;verify-fixpoint>)\\\" on module \\\"<stdin>\\\"\\n2.\\tRunning pass \\\"instcombine<max-iterations=1;verify-fixpoint>\\\" on function \\\"pr119063\\\"\\n #0 0x00007ffff7eb779c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:727:3\\n #1 0x00007ffff7eb5234 llvm::sys::RunSignalHandlers() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Signals.cpp:105:20\\n #2 0x00007ffff7eb558e SignalHandler(int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1\\n #3 0x00007ffff7b3d090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\\n #4 0x00007ffff7b3d00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\\n #5 0x00007ffff7b1c859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\\n #6 0x00007ffff7b1c729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\\n #7 0x00007ffff7b1c729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\\n #8 0x00007ffff7b2dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\\n #9 0x00007ffff2235f91 (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x228f91)\\n#10 0x00007ffff349abca llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::MDNode*) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/IRBuilder.h:2195:41\\n#11 0x00007ffff349abca llvm::IRBuilderBase::CreateIntCast(llvm::Value*, llvm::Type*, bool, llvm::Twine const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/IRBuilder.h:2233:22\\n#12 0x00007ffff34d3d30 llvm::InstCombinerImpl::foldICmpBinOpEqualityWithConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3634:16\\n#13 0x00007ffff34ea16b llvm::InstCombinerImpl::foldICmpInstWithConstant(llvm::ICmpInst&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3502:7\\n#14 0x00007ffff34f9258 llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:7541:50\\n#15 0x00007ffff3455111 llvm::InstCombinerImpl::run() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5201:36\\n#16 0x00007ffff34560d3 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5519:5\\n#17 0x00007ffff3456a7b llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5581:3\\n#18 0x00007ffff4c7e736 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#19 0x00007ffff22b6dcc llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#20 0x00007ffff725b376 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#21 0x00007ffff22b72f9 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/IR/PassManager.cpp:129:41\\n#22 0x00007ffff725bd36 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#23 0x00007ffff22b5215 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#24 0x00007ffff7fa5e63 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:84:5\\n#25 0x00007ffff7fa5e63 llvm::SmallPtrSetImpl<llvm::AnalysisKey*>::~SmallPtrSetImpl() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:363:7\\n#26 0x00007ffff7fa5e63 llvm::SmallPtrSet<llvm::AnalysisKey*, 2u>::~SmallPtrSet() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:519:7\\n#27 0x00007ffff7fa5e63 llvm::PreservedAnalyses::~PreservedAnalyses() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/Analysis.h:111:7\\n#28 0x00007ffff7fa5e63 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/NewPMDriver.cpp:541:10\\n#29 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_data() const /usr/include/c++/10/bits/basic_string.h:195:28\\n#30 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_is_local() const /usr/include/c++/10/bits/basic_string.h:230:23\\n#31 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_dispose() /usr/include/c++/10/bits/basic_string.h:239:18\\n#32 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/include/c++/10/bits/basic_string.h:671:19\\n#33 0x00007ffff7fb065f optMain /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/optdriver.cpp:710:28\\n#34 0x00007ffff7b1e083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\\n#35 0x000055555555509e _start (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt+0x109e)\\n\"\n}\nPlease adjust code according to the feedback. Do not include any additional information.\n"
56
- },
57
- {
58
- "role": "assistant",
59
- "content": "```cpp\n if (match(BOp1, m_APInt(BOC)) && BO->hasOneUse() && RHS->isAllOnesValue()) {\n // Comparing if all bits outside of a constant mask are set?\n // Replace (X | C) == -1 with (X & ~C) == ~C.\n // This removes the -1 constant.\n Constant *NotBOC = ConstantExpr::getNot(cast<Constant>(BOp1));\n Value *And = Builder.CreateAnd(BOp0, NotBOC);\n return new ICmpInst(Pred, And, NotBOC);\n }\n // (icmp eq (or (select cond, 0, NonZero), Other), 0)\n // -> (and cond, (icmp eq Other, 0))\n // (icmp ne (or (select cond, NonZero, 0), Other), 0)\n // -> (or cond, (icmp ne Other, 0))\n Value *Cond, *TV, *FV, *Other, *Sel;\n if (C.isZero() &&\n match(BO,\n m_OneUse(m_c_Or(m_CombineAnd(m_Value(Sel),\n m_Select(m_Value(Cond), m_Value(TV),\n m_Value(FV))),\n m_Value(Other))))) {\n const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);\n // Easy case is if eq/ne matches whether 0 is trueval/falseval.\n if (Pred == ICmpInst::ICMP_EQ\n ? (match(TV, m_Zero()) && isKnownNonZero(FV, Q))\n : (match(FV, m_Zero()) && isKnownNonZero(TV, Q))) {\n Value *Cmp = Builder.CreateICmp(\n Pred, Other, Constant::getNullValue(Other->getType()));\n if (Cmp->getType() != Cond->getType() && \n Cond->getType()->isIntegerTy() && Cmp->getType()->isIntegerTy())\n Cond = Builder.CreateIntCast(Cond, Cmp->getType(), /*isSigned*/false);\n return BinaryOperator::Create(\n Pred == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or, Cmp,\n Cond);\n }\n // Harder case is if eq/ne matches whether 0 is falseval/trueval. In this\n // case we need to invert the select condition so we need to be careful to\n // avoid creating extra instructions.\n // (icmp ne (or (select cond, 0, NonZero), Other), 0)\n // -> (or (not cond), (icmp ne Other, 0))\n // (icmp eq (or (select cond, NonZero, 0), Other), 0)\n // -> (and (not cond), (icmp eq Other, 0))\n```"
60
- },
61
- {
62
- "role": "user",
63
- "content": "Feedback:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll\",\n \"args\": \"opt < %s -passes=instcombine -S\",\n \"name\": \"pr119063\",\n \"body\": \"define <4 x i1> @pr119063(<4 x i32> %x, i1 %cond) {\\nentry:\\n %sel = select i1 %cond, <4 x i32> splat (i32 1), <4 x i32> zeroinitializer\\n %or = or <4 x i32> %sel, %x\\n %cmp = icmp ne <4 x i32> %or, zeroinitializer\\n ret <4 x i1> %cmp\\n}\\n\",\n \"result\": false,\n \"log\": \"Command '['/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt', '-', '-passes=instcombine', '-S']' died with <Signals.SIGABRT: 6>.\\n\\nopt: /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/IR/Instructions.cpp:2642: static llvm::BinaryOperator* llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::InsertPosition): Assertion `S1->getType() == S2->getType() && \\\"Cannot create binary operator with two operands of differing type!\\\"' failed.\\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\\nStack dump:\\n0.\\tProgram arguments: /data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt - -passes=instcombine -S\\n1.\\tRunning pass \\\"function(instcombine<max-iterations=1;verify-fixpoint>)\\\" on module \\\"<stdin>\\\"\\n2.\\tRunning pass \\\"instcombine<max-iterations=1;verify-fixpoint>\\\" on function \\\"pr119063\\\"\\n #0 0x00007ffff7eb779c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:727:3\\n #1 0x00007ffff7eb5234 llvm::sys::RunSignalHandlers() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Signals.cpp:105:20\\n #2 0x00007ffff7eb558e SignalHandler(int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1\\n #3 0x00007ffff7b3d090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\\n #4 0x00007ffff7b3d00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\\n #5 0x00007ffff7b1c859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\\n #6 0x00007ffff7b1c729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\\n #7 0x00007ffff7b1c729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\\n #8 0x00007ffff7b2dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\\n #9 0x00007ffff2233fb4 (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x226fb4)\\n#10 0x00007ffff34d3d1f llvm::InstCombinerImpl::foldICmpBinOpEqualityWithConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3636:38\\n#11 0x00007ffff34ea16b llvm::InstCombinerImpl::foldICmpInstWithConstant(llvm::ICmpInst&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3502:7\\n#12 0x00007ffff34f9258 llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:7542:50\\n#13 0x00007ffff3455111 llvm::InstCombinerImpl::run() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5201:36\\n#14 0x00007ffff34560d3 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5519:5\\n#15 0x00007ffff3456a7b llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5581:3\\n#16 0x00007ffff4c7e736 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#17 0x00007ffff22b6dcc llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#18 0x00007ffff725b376 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#19 0x00007ffff22b72f9 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/IR/PassManager.cpp:129:41\\n#20 0x00007ffff725bd36 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#21 0x00007ffff22b5215 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#22 0x00007ffff7fa5e63 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:84:5\\n#23 0x00007ffff7fa5e63 llvm::SmallPtrSetImpl<llvm::AnalysisKey*>::~SmallPtrSetImpl() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:363:7\\n#24 0x00007ffff7fa5e63 llvm::SmallPtrSet<llvm::AnalysisKey*, 2u>::~SmallPtrSet() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:519:7\\n#25 0x00007ffff7fa5e63 llvm::PreservedAnalyses::~PreservedAnalyses() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/Analysis.h:111:7\\n#26 0x00007ffff7fa5e63 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/NewPMDriver.cpp:541:10\\n#27 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_data() const /usr/include/c++/10/bits/basic_string.h:195:28\\n#28 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_is_local() const /usr/include/c++/10/bits/basic_string.h:230:23\\n#29 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_dispose() /usr/include/c++/10/bits/basic_string.h:239:18\\n#30 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/include/c++/10/bits/basic_string.h:671:19\\n#31 0x00007ffff7fb065f optMain /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/optdriver.cpp:710:28\\n#32 0x00007ffff7b1e083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\\n#33 0x000055555555509e _start (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt+0x109e)\\n\"\n}\nPlease adjust code according to the feedback. Do not include any additional information.\n"
64
- },
65
- {
66
- "role": "assistant",
67
- "content": "```cpp\n if (match(BOp1, m_APInt(BOC)) && BO->hasOneUse() && RHS->isAllOnesValue()) {\n // Comparing if all bits outside of a constant mask are set?\n // Replace (X | C) == -1 with (X & ~C) == ~C.\n // This removes the -1 constant.\n Constant *NotBOC = ConstantExpr::getNot(cast<Constant>(BOp1));\n Value *And = Builder.CreateAnd(BOp0, NotBOC);\n return new ICmpInst(Pred, And, NotBOC);\n }\n // (icmp eq (or (select cond, 0, NonZero), Other), 0)\n // -> (and cond, (icmp eq Other, 0))\n // (icmp ne (or (select cond, NonZero, 0), Other), 0)\n // -> (or cond, (icmp ne Other, 0))\n Value *Cond, *TV, *FV, *Other, *Sel;\n if (C.isZero() &&\n match(BO,\n m_OneUse(m_c_Or(m_CombineAnd(m_Value(Sel),\n m_Select(m_Value(Cond), m_Value(TV),\n m_Value(FV))),\n m_Value(Other))))) {\n const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);\n // Easy case is if eq/ne matches whether 0 is trueval/falseval.\n if (Pred == ICmpInst::ICMP_EQ\n ? (match(TV, m_Zero()) && isKnownNonZero(FV, Q))\n : (match(FV, m_Zero()) && isKnownNonZero(TV, Q))) {\n Value *Cmp = Builder.CreateICmp(\n Pred, Other, Constant::getNullValue(Other->getType()));\n if (Cmp->getType() != Cond->getType() && \n Cond->getType()->isIntegerTy(1) && Cmp->getType()->isIntegerTy(1))\n Cond = Builder.CreateIntCast(Cond, Cmp->getType(), /*isSigned*/false);\n return BinaryOperator::Create(\n Pred == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or, Cmp,\n Cond);\n }\n // Harder case is if eq/ne matches whether 0 is falseval/trueval. In this\n // case we need to invert the select condition so we need to be careful to\n // avoid creating extra instructions.\n // (icmp ne (or (select cond, 0, NonZero), Other), 0)\n // -> (or (not cond), (icmp ne Other, 0))\n // (icmp eq (or (select cond, NonZero, 0), Other), 0)\n // -> (and (not cond), (icmp eq Other, 0))\n```"
68
- },
69
- {
70
- "role": "user",
71
- "content": "Feedback:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll\",\n \"args\": \"opt < %s -passes=instcombine -S\",\n \"name\": \"pr119063\",\n \"body\": \"define <4 x i1> @pr119063(<4 x i32> %x, i1 %cond) {\\nentry:\\n %sel = select i1 %cond, <4 x i32> splat (i32 1), <4 x i32> zeroinitializer\\n %or = or <4 x i32> %sel, %x\\n %cmp = icmp ne <4 x i32> %or, zeroinitializer\\n ret <4 x i1> %cmp\\n}\\n\",\n \"result\": false,\n \"log\": \"Command '['/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt', '-', '-passes=instcombine', '-S']' died with <Signals.SIGABRT: 6>.\\n\\nopt: /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/IR/Instructions.cpp:2642: static llvm::BinaryOperator* llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::InsertPosition): Assertion `S1->getType() == S2->getType() && \\\"Cannot create binary operator with two operands of differing type!\\\"' failed.\\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\\nStack dump:\\n0.\\tProgram arguments: /data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt - -passes=instcombine -S\\n1.\\tRunning pass \\\"function(instcombine<max-iterations=1;verify-fixpoint>)\\\" on module \\\"<stdin>\\\"\\n2.\\tRunning pass \\\"instcombine<max-iterations=1;verify-fixpoint>\\\" on function \\\"pr119063\\\"\\n #0 0x00007ffff7eb779c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:727:3\\n #1 0x00007ffff7eb5234 llvm::sys::RunSignalHandlers() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Signals.cpp:105:20\\n #2 0x00007ffff7eb558e SignalHandler(int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1\\n #3 0x00007ffff7b3d090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\\n #4 0x00007ffff7b3d00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\\n #5 0x00007ffff7b1c859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\\n #6 0x00007ffff7b1c729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\\n #7 0x00007ffff7b1c729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\\n #8 0x00007ffff7b2dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\\n #9 0x00007ffff2233fb4 (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x226fb4)\\n#10 0x00007ffff34d3d49 llvm::InstCombinerImpl::foldICmpBinOpEqualityWithConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3636:38\\n#11 0x00007ffff34ea17b llvm::InstCombinerImpl::foldICmpInstWithConstant(llvm::ICmpInst&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3502:7\\n#12 0x00007ffff34f9268 llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:7542:50\\n#13 0x00007ffff3455111 llvm::InstCombinerImpl::run() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5201:36\\n#14 0x00007ffff34560d3 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5519:5\\n#15 0x00007ffff3456a7b llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5581:3\\n#16 0x00007ffff4c7e736 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#17 0x00007ffff22b6dcc llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#18 0x00007ffff725b376 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#19 0x00007ffff22b72f9 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/IR/PassManager.cpp:129:41\\n#20 0x00007ffff725bd36 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#21 0x00007ffff22b5215 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#22 0x00007ffff7fa5e63 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:84:5\\n#23 0x00007ffff7fa5e63 llvm::SmallPtrSetImpl<llvm::AnalysisKey*>::~SmallPtrSetImpl() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:363:7\\n#24 0x00007ffff7fa5e63 llvm::SmallPtrSet<llvm::AnalysisKey*, 2u>::~SmallPtrSet() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:519:7\\n#25 0x00007ffff7fa5e63 llvm::PreservedAnalyses::~PreservedAnalyses() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/Analysis.h:111:7\\n#26 0x00007ffff7fa5e63 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/NewPMDriver.cpp:541:10\\n#27 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_data() const /usr/include/c++/10/bits/basic_string.h:195:28\\n#28 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_is_local() const /usr/include/c++/10/bits/basic_string.h:230:23\\n#29 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_dispose() /usr/include/c++/10/bits/basic_string.h:239:18\\n#30 0x00007ffff7fb065f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/include/c++/10/bits/basic_string.h:671:19\\n#31 0x00007ffff7fb065f optMain /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/optdriver.cpp:710:28\\n#32 0x00007ffff7b1e083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\\n#33 0x000055555555509e _start (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt+0x109e)\\n\"\n}\nPlease adjust code according to the feedback. Do not include any additional information.\n"
72
- }
73
- ]
74
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
examples/fixes/120361.json DELETED
@@ -1,74 +0,0 @@
1
- {
2
- "wall_time": 66.45176982879639,
3
- "knowledge": [
4
- [
5
- "base_model",
6
- "2023-12-31+0000"
7
- ],
8
- [
9
- "hint:bug_functions",
10
- "2024-12-18+0000"
11
- ],
12
- [
13
- "hint:components",
14
- "2024-12-18+0000"
15
- ],
16
- [
17
- "hint:issue",
18
- "2024-12-18+0000"
19
- ],
20
- [
21
- "hint:line_level_bug_locations",
22
- "2024-12-18+0000"
23
- ]
24
- ],
25
- "build_count": 5,
26
- "build_failure_count": 3,
27
- "fast_check_count": 1,
28
- "full_check_count": 4,
29
- "fast_check_pass": false,
30
- "full_check_pass": false,
31
- "patch": "diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\nindex dff9304be64d..6419b0ce86f9 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\n@@ -437,7 +437,7 @@ static Value *foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed(\n \n // At this point, either B is a superset of D, B is a subset of D or B == D.\n \n- // If E is zero, if B is a subset of (or equal to) D, LHS and RHS contradict\n+// If E is zero, if B is a subset of (or equal to) D, LHS and RHS contradict\n // and the whole expression becomes false (or true if negated), otherwise, no\n // folding.\n // For example,\n@@ -455,14 +455,28 @@ static Value *foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed(\n // RHS. For example,\n // (icmp ne (A & 255), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n // (icmp ne (A & 15), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n- if (IsSuperSetOrEqual(BCst, DCst))\n+ if (IsSuperSetOrEqual(BCst, DCst)) {\n+ // If RHS is a samesign icmp, we can't fold to RHS because it may introduce\n+ // poison when LHS is false.\n+ if (RHS->getPredicate() == ICmpInst::ICMP_EQ &&\n+ isa<ConstantInt>(RHS->getOperand(1)) &&\n+ cast<ConstantInt>(RHS->getOperand(1))->isAllOnesValue())\n+ return nullptr;\n return RHS;\n+ }\n // Otherwise, B is a subset of D. If B and E have a common bit set,\n // ie. (B & E) != 0, then LHS is subsumed by RHS. For example.\n // (icmp ne (A & 12), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n assert(IsSubSetOrEqual(BCst, DCst) && \"Precondition due to above code\");\n- if ((*BCst & ECst) != 0)\n+ if ((*BCst & ECst) != 0) {\n+ // If RHS is a samesign icmp, we can't fold to RHS because it may introduce\n+ // poison when LHS is false.\n+ if (RHS->getPredicate() == ICmpInst::ICMP_EQ &&\n+ isa<ConstantInt>(RHS->getOperand(1)) &&\n+ cast<ConstantInt>(RHS->getOperand(1))->isAllOnesValue())\n+ return nullptr;\n return RHS;\n+ }\n // Otherwise, LHS and RHS contradict and the whole expression becomes false\n // (or true if negated.) For example,\n // (icmp ne (A & 7), 0) & (icmp eq (A & 15), 8) -> false.\n",
32
- "log": [
33
- {
34
- "role": "system",
35
- "content": "You are an LLVM maintainer.\nYou are fixing a middle-end bug in the LLVM project.\nPlease answer with the code directly. Do not include any additional information.\n"
36
- },
37
- {
38
- "role": "user",
39
- "content": "This is a miscompilation bug in InstCombine.\nIssue title: [InstCombine] `samesign` should be dropped when folding logical and of icmps\nIssue body: Reproducer: https://alive2.llvm.org/ce/z/YSW_NC\n```\ndefine i1 @src(i8 %0, i8 %1) {\nstart:\n %2 = icmp samesign eq i8 %0, -1\n %3 = icmp ne i8 %0, 0\n %4 = icmp ugt i8 %0, %0\n %result = select i1 %3, i1 %2, i1 %4\n ret i1 %result\n}\n\ndefine i1 @tgt(i8 %0, i8 %1) {\nstart:\n %2 = icmp samesign eq i8 %0, -1\n ret i1 %2\n}\n```\n```\n\n----------------------------------------\ndefine i1 @src(i8 %#0, i8 %#1) {\nstart:\n %#2 = icmp samesign eq i8 %#0, 255\n %#3 = icmp ne i8 %#0, 0\n %#4 = icmp ugt i8 %#0, %#0\n %result = select i1 %#3, i1 %#2, i1 %#4\n ret i1 %result\n}\n=>\ndefine i1 @tgt(i8 %#0, i8 %#1) {\nstart:\n %#2 = icmp samesign eq i8 %#0, 255\n ret i1 %#2\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\ni8 %#0 = #x00 (0)\ni8 %#1 = poison\n\nSource:\ni1 %#2 = poison\ni1 %#3 = #x0 (0)\ni1 %#4 = #x0 (0)\ni1 %result = #x0 (0)\n\nTarget:\ni1 %#2 = poison\nSource value: #x0 (0)\nTarget value: poison\n```\nReported by https://github.com/dtcxzyw/llvm-mutation-based-fuzz-service/issues/14 while reviewing https://github.com/llvm/llvm-project/pull/120177.\n\n\n\nDetailed information:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/icmp-logical.ll\",\n \"args\": \"opt -passes=instcombine -S -o - %s\",\n \"name\": \"pr120361\",\n \"body\": \"define i1 @pr120361(i8 %x, i8 %y) {\\n %cmp1 = icmp samesign eq i8 %x, -1\\n %cmp2 = icmp ne i8 %x, 0\\n %result = select i1 %cmp2, i1 %cmp1, i1 false\\n ret i1 %result\\n}\\n\",\n \"result\": false,\n \"log\": {\n \"src\": \"define i1 @pr120361(i8 %x, i8 %y) {\\n %cmp1 = icmp samesign eq i8 %x, -1\\n %cmp2 = icmp ne i8 %x, 0\\n %result = select i1 %cmp2, i1 %cmp1, i1 false\\n ret i1 %result\\n}\\n\",\n \"tgt\": \"; ModuleID = '<stdin>'\\nsource_filename = \\\"<stdin>\\\"\\n\\ndefine i1 @pr120361(i8 %x, i8 %y) {\\n %cmp1 = icmp samesign eq i8 %x, -1\\n ret i1 %cmp1\\n}\\n\",\n \"log\": \"\\n----------------------------------------\\ndefine i1 @pr120361(i8 %x, i8 %y) {\\n#0:\\n %cmp1 = icmp samesign eq i8 %x, 255\\n %cmp2 = icmp ne i8 %x, 0\\n %result = select i1 %cmp2, i1 %cmp1, i1 0\\n ret i1 %result\\n}\\n=>\\ndefine i1 @pr120361(i8 %x, i8 %y) {\\n#0:\\n %cmp1 = icmp samesign eq i8 %x, 255\\n ret i1 %cmp1\\n}\\nTransformation doesn't verify!\\n\\nERROR: Target is more poisonous than source\\n\\nExample:\\ni8 %x = #x00 (0)\\ni8 %y = poison\\n\\nSource:\\ni1 %cmp1 = poison\\ni1 %cmp2 = #x0 (0)\\ni1 %result = #x0 (0)\\n\\nTarget:\\ni1 %cmp1 = poison\\nSource value: #x0 (0)\\nTarget value: poison\\n\\nSummary:\\n 0 correct transformations\\n 1 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n\",\n \"opt_stderr\": \"\"\n }\n}\nPlease modify the following code in llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed to fix the bug:\n```\n // If E is zero, if B is a subset of (or equal to) D, LHS and RHS contradict\n // and the whole expression becomes false (or true if negated), otherwise, no\n // folding.\n // For example,\n // (icmp ne (A & 3), 0) & (icmp eq (A & 7), 0) -> false.\n // (icmp ne (A & 15), 0) & (icmp eq (A & 3), 0) -> no folding.\n if (ECst.isZero()) {\n if (IsSubSetOrEqual(BCst, DCst))\n return ConstantInt::get(LHS->getType(), !IsAnd);\n return nullptr;\n }\n\n // At this point, B, D, E aren't zero and (B & D) == B, (B & D) == D or B ==\n // D. If B is a superset of (or equal to) D, since E is not zero, LHS is\n // subsumed by RHS (RHS implies LHS.) So the whole expression becomes\n // RHS. For example,\n // (icmp ne (A & 255), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n // (icmp ne (A & 15), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n if (IsSuperSetOrEqual(BCst, DCst))\n return RHS;\n // Otherwise, B is a subset of D. If B and E have a common bit set,\n // ie. (B & E) != 0, then LHS is subsumed by RHS. For example.\n // (icmp ne (A & 12), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n assert(IsSubSetOrEqual(BCst, DCst) && \"Precondition due to above code\");\n if ((*BCst & ECst) != 0)\n return RHS;\n // Otherwise, LHS and RHS contradict and the whole expression becomes false\n // (or true if negated.) For example,\n // (icmp ne (A & 7), 0) & (icmp eq (A & 15), 8) -> false.\n // (icmp ne (A & 6), 0) & (icmp eq (A & 15), 8) -> false.\n return ConstantInt::get(LHS->getType(), !IsAnd);\n}\n\n/// Try to fold (icmp(A & B) ==/!= 0) &/| (icmp(A & D) ==/!= E) into a single\n/// (icmp(A & X) ==/!= Y), where the left-hand side and the right hand side\n/// aren't of the common mask pattern type.\n/// Also used for logical and/or, must be poison safe.\nstatic Value *foldLogOpOfMaskedICmpsAsymmetric(\n ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, Value *A, Value *B, Value *C,\n Value *D, Value *E, ICmpInst::Predicate PredL, ICmpInst::Predicate PredR,\n unsigned LHSMask, unsigned RHSMask, InstCombiner::BuilderTy &Builder) {\n assert(ICmpInst::isEquality(PredL) && ICmpInst::isEquality(PredR) &&\n \"Expected equality predicates for masked type of icmps.\");\n // Handle Mask_NotAllZeros-BMask_Mixed cases.\n```\n"
40
- },
41
- {
42
- "role": "assistant",
43
- "content": "```cpp\n // If E is zero, if B is a subset of (or equal to) D, LHS and RHS contradict\n // and the whole expression becomes false (or true if negated), otherwise, no\n // folding.\n // For example,\n // (icmp ne (A & 3), 0) & (icmp eq (A & 7), 0) -> false.\n // (icmp ne (A & 15), 0) & (icmp eq (A & 3), 0) -> no folding.\n if (ECst.isZero()) {\n if (IsSubSetOrEqual(BCst, DCst))\n return ConstantInt::get(LHS->getType(), !IsAnd);\n return nullptr;\n }\n\n // At this point, B, D, E aren't zero and (B & D) == B, (B & D) == D or B ==\n // D. If B is a superset of (or equal to) D, since E is not zero, LHS is\n // subsumed by RHS (RHS implies LHS.) So the whole expression becomes\n // RHS. For example,\n // (icmp ne (A & 255), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n // (icmp ne (A & 15), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n if (IsSuperSetOrEqual(BCst, DCst)) {\n // If RHS is a samesign icmp, we can't fold to RHS because it may introduce\n // poison when LHS is false.\n if (RHS->getPredicate() == ICmpInst::ICMP_SAMESIGN)\n return nullptr;\n return RHS;\n }\n // Otherwise, B is a subset of D. If B and E have a common bit set,\n // ie. (B & E) != 0, then LHS is subsumed by RHS. For example.\n // (icmp ne (A & 12), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n assert(IsSubSetOrEqual(BCst, DCst) && \"Precondition due to above code\");\n if ((*BCst & ECst) != 0) {\n // If RHS is a samesign icmp, we can't fold to RHS because it may introduce\n // poison when LHS is false.\n if (RHS->getPredicate() == ICmpInst::ICMP_SAMESIGN)\n return nullptr;\n return RHS;\n }\n // Otherwise, LHS and RHS contradict and the whole expression becomes false\n // (or true if negated.) For example,\n // (icmp ne (A & 7), 0) & (icmp eq (A & 15), 8) -> false.\n // (icmp ne (A & 6), 0) & (icmp eq (A & 15), 8) -> false.\n return ConstantInt::get(LHS->getType(), !IsAnd);\n}\n```"
44
- },
45
- {
46
- "role": "user",
47
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (6.0s)\n-- Generating done (3.1s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/85] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/85] Linking CXX executable bin/llvm-config\n[3/85] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp: In function \u2018llvm::Value* foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed(llvm::ICmpInst*, llvm::ICmpInst*, bool, llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, llvm::CmpInst::Predicate, llvm::CmpInst::Predicate, llvm::InstCombiner::BuilderTy&)\u2019:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:461:42: error: \u2018ICMP_SAMESIGN\u2019 is not a member of \u2018llvm::ICmpInst\u2019\n 461 | if (RHS->getPredicate() == ICmpInst::ICMP_SAMESIGN)\n | ^~~~~~~~~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:472:42: error: \u2018ICMP_SAMESIGN\u2019 is not a member of \u2018llvm::ICmpInst\u2019\n 472 | if (RHS->getPredicate() == ICmpInst::ICMP_SAMESIGN)\n | ^~~~~~~~~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp: At global scope:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:486:3: error: expected unqualified-id before \u2018if\u2019\n 486 | if (!IsAnd) {\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:490:3: error: expected unqualified-id before \u2018if\u2019\n 490 | if ((LHSMask & Mask_NotAllZeros) && (RHSMask & BMask_Mixed)) {\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:495:5: error: expected unqualified-id before \u2018else\u2019\n 495 | } else if ((LHSMask & BMask_Mixed) && (RHSMask & Mask_NotAllZeros)) {\n | ^~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:501:3: error: expected unqualified-id before \u2018return\u2019\n 501 | return nullptr;\n | ^~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:502:1: error: expected declaration before \u2018}\u2019 token\n 502 | }\n | ^\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp: In function \u2018llvm::Value* foldLogOpOfMaskedICmps(llvm::ICmpInst*, llvm::ICmpInst*, bool, bool, llvm::InstCombiner::BuilderTy&)\u2019:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:523:20: error: \u2018foldLogOpOfMaskedICmpsAsymmetric\u2019 was not declared in this scope; did you mean \u2018foldLogOpOfMaskedICmps\u2019?\n 523 | if (Value *V = foldLogOpOfMaskedICmpsAsymmetric(\n | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n | foldLogOpOfMaskedICmps\nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback. Do not include any additional information.\n"
48
- },
49
- {
50
- "role": "assistant",
51
- "content": "```cpp\n // If E is zero, if B is a subset of (or equal to) D, LHS and RHS contradict\n // and the whole expression becomes false (or true if negated), otherwise, no\n // folding.\n // For example,\n // (icmp ne (A & 3), 0) & (icmp eq (A & 7), 0) -> false.\n // (icmp ne (A & 15), 0) & (icmp eq (A & 3), 0) -> no folding.\n if (ECst.isZero()) {\n if (IsSubSetOrEqual(BCst, DCst))\n return ConstantInt::get(LHS->getType(), !IsAnd);\n return nullptr;\n }\n\n // At this point, B, D, E aren't zero and (B & D) == B, (B & D) == D or B ==\n // D. If B is a superset of (or equal to) D, since E is not zero, LHS is\n // subsumed by RHS (RHS implies LHS.) So the whole expression becomes\n // RHS. For example,\n // (icmp ne (A & 255), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n // (icmp ne (A & 15), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n if (IsSuperSetOrEqual(BCst, DCst)) {\n // If RHS is a samesign icmp, we can't fold to RHS because it may introduce\n // poison when LHS is false.\n if (RHS->getPredicate() == ICmpInst::ICMP_EQ &&\n RHS->getOperand(1) == ConstantInt::get(RHS->getOperand(1)->getType(), -1))\n return nullptr;\n return RHS;\n }\n // Otherwise, B is a subset of D. If B and E have a common bit set,\n // ie. (B & E) != 0, then LHS is subsumed by RHS. For example.\n // (icmp ne (A & 12), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n assert(IsSubSetOrEqual(BCst, DCst) && \"Precondition due to above code\");\n if ((*BCst & ECst) != 0) {\n // If RHS is a samesign icmp, we can't fold to RHS because it may introduce\n // poison when LHS is false.\n if (RHS->getPredicate() == ICmpInst::ICMP_EQ &&\n RHS->getOperand(1) == ConstantInt::get(RHS->getOperand(1)->getType(), -1))\n return nullptr;\n return RHS;\n }\n // Otherwise, LHS and RHS contradict and the whole expression becomes false\n // (or true if negated.) For example,\n // (icmp ne (A & 7), 0) & (icmp eq (A & 15), 8) -> false.\n // (icmp ne (A & 6), 0) & (icmp eq (A & 15), 8) -> false.\n return ConstantInt::get(LHS->getType(), !IsAnd);\n}\n```"
52
- },
53
- {
54
- "role": "user",
55
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (5.8s)\n-- Generating done (3.1s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/85] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/85] Linking CXX executable bin/llvm-config\n[3/85] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:488:3: error: expected unqualified-id before \u2018if\u2019\n 488 | if (!IsAnd) {\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:492:3: error: expected unqualified-id before \u2018if\u2019\n 492 | if ((LHSMask & Mask_NotAllZeros) && (RHSMask & BMask_Mixed)) {\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:497:5: error: expected unqualified-id before \u2018else\u2019\n 497 | } else if ((LHSMask & BMask_Mixed) && (RHSMask & Mask_NotAllZeros)) {\n | ^~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:503:3: error: expected unqualified-id before \u2018return\u2019\n 503 | return nullptr;\n | ^~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:504:1: error: expected declaration before \u2018}\u2019 token\n 504 | }\n | ^\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp: In function \u2018llvm::Value* foldLogOpOfMaskedICmps(llvm::ICmpInst*, llvm::ICmpInst*, bool, bool, llvm::InstCombiner::BuilderTy&)\u2019:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:525:20: error: \u2018foldLogOpOfMaskedICmpsAsymmetric\u2019 was not declared in this scope; did you mean \u2018foldLogOpOfMaskedICmps\u2019?\n 525 | if (Value *V = foldLogOpOfMaskedICmpsAsymmetric(\n | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n | foldLogOpOfMaskedICmps\nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback. Do not include any additional information.\n"
56
- },
57
- {
58
- "role": "assistant",
59
- "content": "```cpp\n // If E is zero, if B is a subset of (or equal to) D, LHS and RHS contradict\n // and the whole expression becomes false (or true if negated), otherwise, no\n // folding.\n // For example,\n // (icmp ne (A & 3), 0) & (icmp eq (A & 7), 0) -> false.\n // (icmp ne (A & 15), 0) & (icmp eq (A & 3), 0) -> no folding.\n if (ECst.isZero()) {\n if (IsSubSetOrEqual(BCst, DCst))\n return ConstantInt::get(LHS->getType(), !IsAnd);\n return nullptr;\n }\n\n // At this point, B, D, E aren't zero and (B & D) == B, (B & D) == D or B ==\n // D. If B is a superset of (or equal to) D, since E is not zero, LHS is\n // subsumed by RHS (RHS implies LHS.) So the whole expression becomes\n // RHS. For example,\n // (icmp ne (A & 255), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n // (icmp ne (A & 15), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n if (IsSuperSetOrEqual(BCst, DCst)) {\n // If RHS is a samesign icmp, we can't fold to RHS because it may introduce\n // poison when LHS is false.\n if (RHS->getPredicate() == ICmpInst::ICMP_EQ &&\n isa<ConstantInt>(RHS->getOperand(1)) &&\n cast<ConstantInt>(RHS->getOperand(1))->isAllOnesValue())\n return nullptr;\n return RHS;\n }\n // Otherwise, B is a subset of D. If B and E have a common bit set,\n // ie. (B & E) != 0, then LHS is subsumed by RHS. For example.\n // (icmp ne (A & 12), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n assert(IsSubSetOrEqual(BCst, DCst) && \"Precondition due to above code\");\n if ((*BCst & ECst) != 0) {\n // If RHS is a samesign icmp, we can't fold to RHS because it may introduce\n // poison when LHS is false.\n if (RHS->getPredicate() == ICmpInst::ICMP_EQ &&\n isa<ConstantInt>(RHS->getOperand(1)) &&\n cast<ConstantInt>(RHS->getOperand(1))->isAllOnesValue())\n return nullptr;\n return RHS;\n }\n // Otherwise, LHS and RHS contradict and the whole expression becomes false\n // (or true if negated.) For example,\n // (icmp ne (A & 7), 0) & (icmp eq (A & 15), 8) -> false.\n // (icmp ne (A & 6), 0) & (icmp eq (A & 15), 8) -> false.\n return ConstantInt::get(LHS->getType(), !IsAnd);\n}\n```"
60
- },
61
- {
62
- "role": "user",
63
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (5.7s)\n-- Generating done (3.1s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/85] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/85] Linking CXX executable bin/llvm-config\n[3/85] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineAndOrXor.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:490:3: error: expected unqualified-id before \u2018if\u2019\n 490 | if (!IsAnd) {\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:494:3: error: expected unqualified-id before \u2018if\u2019\n 494 | if ((LHSMask & Mask_NotAllZeros) && (RHSMask & BMask_Mixed)) {\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:499:5: error: expected unqualified-id before \u2018else\u2019\n 499 | } else if ((LHSMask & BMask_Mixed) && (RHSMask & Mask_NotAllZeros)) {\n | ^~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:505:3: error: expected unqualified-id before \u2018return\u2019\n 505 | return nullptr;\n | ^~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:506:1: error: expected declaration before \u2018}\u2019 token\n 506 | }\n | ^\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp: In function \u2018llvm::Value* foldLogOpOfMaskedICmps(llvm::ICmpInst*, llvm::ICmpInst*, bool, bool, llvm::InstCombiner::BuilderTy&)\u2019:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:527:20: error: \u2018foldLogOpOfMaskedICmpsAsymmetric\u2019 was not declared in this scope; did you mean \u2018foldLogOpOfMaskedICmps\u2019?\n 527 | if (Value *V = foldLogOpOfMaskedICmpsAsymmetric(\n | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n | foldLogOpOfMaskedICmps\nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback. Do not include any additional information.\n"
64
- },
65
- {
66
- "role": "assistant",
67
- "content": "```cpp\n // If E is zero, if B is a subset of (or equal to) D, LHS and RHS contradict\n // and the whole expression becomes false (or true if negated), otherwise, no\n // folding.\n // For example,\n // (icmp ne (A & 3), 0) & (icmp eq (A & 7), 0) -> false.\n // (icmp ne (A & 15), 0) & (icmp eq (A & 3), 0) -> no folding.\n if (ECst.isZero()) {\n if (IsSubSetOrEqual(BCst, DCst))\n return ConstantInt::get(LHS->getType(), !IsAnd);\n return nullptr;\n }\n\n // At this point, B, D, E aren't zero and (B & D) == B, (B & D) == D or B ==\n // D. If B is a superset of (or equal to) D, since E is not zero, LHS is\n // subsumed by RHS (RHS implies LHS.) So the whole expression becomes\n // RHS. For example,\n // (icmp ne (A & 255), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n // (icmp ne (A & 15), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n if (IsSuperSetOrEqual(BCst, DCst)) {\n // If RHS is a samesign icmp, we can't fold to RHS because it may introduce\n // poison when LHS is false.\n if (RHS->getPredicate() == ICmpInst::ICMP_EQ &&\n isa<ConstantInt>(RHS->getOperand(1)) &&\n cast<ConstantInt>(RHS->getOperand(1))->isAllOnesValue())\n return nullptr;\n return RHS;\n }\n // Otherwise, B is a subset of D. If B and E have a common bit set,\n // ie. (B & E) != 0, then LHS is subsumed by RHS. For example.\n // (icmp ne (A & 12), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).\n assert(IsSubSetOrEqual(BCst, DCst) && \"Precondition due to above code\");\n if ((*BCst & ECst) != 0) {\n // If RHS is a samesign icmp, we can't fold to RHS because it may introduce\n // poison when LHS is false.\n if (RHS->getPredicate() == ICmpInst::ICMP_EQ &&\n isa<ConstantInt>(RHS->getOperand(1)) &&\n cast<ConstantInt>(RHS->getOperand(1))->isAllOnesValue())\n return nullptr;\n return RHS;\n }\n // Otherwise, LHS and RHS contradict and the whole expression becomes false\n // (or true if negated.) For example,\n // (icmp ne (A & 7), 0) & (icmp eq (A & 15), 8) -> false.\n // (icmp ne (A & 6), 0) & (icmp eq (A & 15), 8) -> false.\n return ConstantInt::get(LHS->getType(), !IsAnd);\n}\n\n/// Try to fold (icmp(A & B) ==/!= 0) &/| (icmp(A & D) ==/!= E) into a single\n/// (icmp(A & X) ==/!= Y), where the left-hand side and the right hand side\n/// aren't of the common mask pattern type.\n/// Also used for logical and/or, must be poison safe.\nstatic Value *foldLogOpOfMaskedICmpsAsymmetric(\n ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, Value *A, Value *B, Value *C,\n Value *D, Value *E, ICmpInst::Predicate PredL, ICmpInst::Predicate PredR,\n unsigned LHSMask, unsigned RHSMask, InstCombiner::BuilderTy &Builder) {\n assert(ICmpInst::isEquality(PredL) && ICmpInst::isEquality(PredR) &&\n \"Expected equality predicates for masked type of icmps.\");\n // Handle Mask_NotAllZeros-BMask_Mixed cases.\n```"
68
- },
69
- {
70
- "role": "user",
71
- "content": "Feedback:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/icmp-logical.ll\",\n \"args\": \"opt -passes=instcombine -S -o - %s\",\n \"name\": \"pr120361_v2\",\n \"body\": \"define i1 @pr120361_v2(i32 %x) {\\n %and1 = and i32 %x, 15\\n %cmp1 = icmp ne i32 %and1, 0\\n %and2 = and i32 %x, -113\\n %cmp2 = icmp samesign eq i32 %and2, 15\\n %and = select i1 %cmp1, i1 %cmp2, i1 false\\n ret i1 %and\\n}\\n\",\n \"result\": false,\n \"log\": {\n \"src\": \"define i1 @pr120361_v2(i32 %x) {\\n %and1 = and i32 %x, 15\\n %cmp1 = icmp ne i32 %and1, 0\\n %and2 = and i32 %x, -113\\n %cmp2 = icmp samesign eq i32 %and2, 15\\n %and = select i1 %cmp1, i1 %cmp2, i1 false\\n ret i1 %and\\n}\\n\",\n \"tgt\": \"; ModuleID = '<stdin>'\\nsource_filename = \\\"<stdin>\\\"\\n\\ndefine i1 @pr120361_v2(i32 %x) {\\n %and2 = and i32 %x, -113\\n %cmp2 = icmp samesign eq i32 %and2, 15\\n ret i1 %cmp2\\n}\\n\",\n \"log\": \"\\n----------------------------------------\\ndefine i1 @pr120361_v2(i32 %x) {\\n#0:\\n %and1 = and i32 %x, 15\\n %cmp1 = icmp ne i32 %and1, 0\\n %and2 = and i32 %x, 4294967183\\n %cmp2 = icmp samesign eq i32 %and2, 15\\n %and = select i1 %cmp1, i1 %cmp2, i1 0\\n ret i1 %and\\n}\\n=>\\ndefine i1 @pr120361_v2(i32 %x) {\\n#0:\\n %and2 = and i32 %x, 4294967183\\n %cmp2 = icmp samesign eq i32 %and2, 15\\n ret i1 %cmp2\\n}\\nTransformation doesn't verify!\\n\\nERROR: Target is more poisonous than source\\n\\nExample:\\ni32 %x = #x80000000 (2147483648, -2147483648)\\n\\nSource:\\ni32 %and1 = #x00000000 (0)\\ni1 %cmp1 = #x0 (0)\\ni32 %and2 = #x80000000 (2147483648, -2147483648)\\ni1 %cmp2 = poison\\ni1 %and = #x0 (0)\\n\\nTarget:\\ni32 %and2 = #x80000000 (2147483648, -2147483648)\\ni1 %cmp2 = poison\\nSource value: #x0 (0)\\nTarget value: poison\\n\\nSummary:\\n 0 correct transformations\\n 1 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n\",\n \"opt_stderr\": \"\"\n }\n}\nPlease adjust code according to the feedback. Do not include any additional information.\n"
72
- }
73
- ]
74
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
examples/fixes/121110.json DELETED
The diff for this file is too large to render. See raw diff
 
examples/fixes/121428.json DELETED
@@ -1,46 +0,0 @@
1
- {
2
- "wall_time": 6.274488687515259,
3
- "knowledge": [
4
- [
5
- "base_model",
6
- "2023-12-31+0000"
7
- ],
8
- [
9
- "hint:bug_functions",
10
- "2025-01-01+0000"
11
- ],
12
- [
13
- "hint:components",
14
- "2025-01-01+0000"
15
- ],
16
- [
17
- "hint:issue",
18
- "2025-01-01+0000"
19
- ],
20
- [
21
- "hint:line_level_bug_locations",
22
- "2025-01-01+0000"
23
- ]
24
- ],
25
- "build_count": 2,
26
- "build_failure_count": 0,
27
- "fast_check_count": 1,
28
- "full_check_count": 1,
29
- "fast_check_pass": true,
30
- "full_check_pass": true,
31
- "patch": "diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp\nindex e7a8e947705f..3ddf906b622a 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp\n@@ -1217,7 +1217,7 @@ static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal,\n II->setArgOperand(1, ConstantInt::getFalse(II->getContext()));\n // A range annotation on the intrinsic may no longer be valid.\n II->dropPoisonGeneratingAnnotations();\n- IC.addToWorklist(II);\n+IC.addToWorklist(II);\n return SelectArg;\n }\n \n@@ -1225,8 +1225,12 @@ static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal,\n // zext/trunc) have one use (ending at the select), the cttz/ctlz result will\n // not be used if the input is zero. Relax to 'zero is poison' for that case.\n if (II->hasOneUse() && SelectArg->hasOneUse() &&\n- !match(II->getArgOperand(1), m_One()))\n+ !match(II->getArgOperand(1), m_One())) {\n II->setArgOperand(1, ConstantInt::getTrue(II->getContext()));\n+ // Drop noundef attribute since the result may be poison now\n+ if (II->hasRetAttr(Attribute::NoUndef))\n+ II->removeRetAttr(Attribute::NoUndef);\n+ }\n \n return nullptr;\n }\n",
32
- "log": [
33
- {
34
- "role": "system",
35
- "content": "You are an LLVM maintainer.\nYou are fixing a middle-end bug in the LLVM project.\nPlease answer with the code directly. Do not include any additional information.\n"
36
- },
37
- {
38
- "role": "user",
39
- "content": "This is a miscompilation bug in InstCombine.\nIssue title: [InstCombine] `noundef` attribute should be dropped\nIssue body: Alive2: https://alive2.llvm.org/ce/z/wKsUWK\n```\ndefine i32 @src(i32 noundef %x) {\n %ct = call noundef i32 @llvm.cttz.i32(i32 %x, i1 false)\n %cmp = icmp ne i32 %x, 0\n %res = select i1 %cmp, i32 %ct, i32 123\n ret i32 %res\n}\ndefine i32 @tgt(i32 noundef %x) {\n %ct = call noundef range(i32 0, 33) i32 @llvm.cttz.i32(i32 %x, i1 true)\n %cmp.not = icmp eq i32 %x, 0\n %res = select i1 %cmp.not, i32 123, i32 %ct\n ret i32 %res\n}\n```\n\nDetailed information:\n[{'file': 'llvm/test/Transforms/InstCombine/select-cmp-cttz-ctlz.ll', 'args': 'opt -passes=instcombine -S < %s', 'name': 'test_cttz_not_bw_multiuse', 'body': 'define i32 @test_cttz_not_bw_multiuse(i32 %x) {\\n %ct = tail call i32 @llvm.cttz.i32(i32 %x, i1 false)\\n %cmp = icmp ne i32 %x, 0\\n %sel = select i1 %cmp, i32 %ct, i32 123\\n %res = or i32 %sel, %ct\\n ret i32 %res\\n}\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n', 'result': True, 'log': {'src': 'define i32 @test_cttz_not_bw_multiuse(i32 %x) {\\n %ct = tail call i32 @llvm.cttz.i32(i32 %x, i1 false)\\n %cmp = icmp ne i32 %x, 0\\n %sel = select i1 %cmp, i32 %ct, i32 123\\n %res = or i32 %sel, %ct\\n ret i32 %res\\n}\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n', 'tgt': '; ModuleID = \\'<stdin>\\'\\nsource_filename = \"<stdin>\"\\n\\ndefine i32 @test_cttz_not_bw_multiuse(i32 %x) {\\n %ct = tail call range(i32 0, 33) i32 @llvm.cttz.i32(i32 %x, i1 false)\\n %cmp.not = icmp eq i32 %x, 0\\n %sel = select i1 %cmp.not, i32 123, i32 %ct\\n %res = or i32 %sel, %ct\\n ret i32 %res\\n}\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n', 'log': '\\n----------------------------------------\\ndefine i32 @test_cttz_not_bw_multiuse(i32 %x) {\\n#0:\\n %ct = cttz i32 %x, 0\\n %cmp = icmp ne i32 %x, 0\\n %sel = select i1 %cmp, i32 %ct, i32 123\\n %res = or i32 %sel, %ct\\n ret i32 %res\\n}\\n=>\\ndefine i32 @test_cttz_not_bw_multiuse(i32 %x) {\\n#0:\\n %ct = cttz i32 %x, 0\\n %#range_0_%ct = !range i32 %ct, i32 0, i32 33\\n %cmp.not = icmp eq i32 %x, 0\\n %sel = select i1 %cmp.not, i32 123, i32 %#range_0_%ct\\n %res = or i32 %sel, %#range_0_%ct\\n ret i32 %res\\n}\\nTransformation seems to be correct!\\n\\nSummary:\\n 1 correct transformations\\n 0 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n', 'opt_stderr': ''}}, {'file': 'llvm/test/Transforms/InstCombine/select-cmp-cttz-ctlz.ll', 'args': 'opt -passes=instcombine -S < %s', 'name': 'test_cttz_not_bw', 'body': 'define i32 @test_cttz_not_bw(i32 %x) {\\n %ct = tail call i32 @llvm.cttz.i32(i32 %x, i1 false)\\n %cmp = icmp ne i32 %x, 0\\n %res = select i1 %cmp, i32 %ct, i32 123\\n ret i32 %res\\n}\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n', 'result': True, 'log': {'src': 'define i32 @test_cttz_not_bw(i32 %x) {\\n %ct = tail call i32 @llvm.cttz.i32(i32 %x, i1 false)\\n %cmp = icmp ne i32 %x, 0\\n %res = select i1 %cmp, i32 %ct, i32 123\\n ret i32 %res\\n}\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n', 'tgt': '; ModuleID = \\'<stdin>\\'\\nsource_filename = \"<stdin>\"\\n\\ndefine i32 @test_cttz_not_bw(i32 %x) {\\n %ct = tail call range(i32 0, 33) i32 @llvm.cttz.i32(i32 %x, i1 true)\\n %cmp.not = icmp eq i32 %x, 0\\n %res = select i1 %cmp.not, i32 123, i32 %ct\\n ret i32 %res\\n}\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n', 'log': '\\n----------------------------------------\\ndefine i32 @test_cttz_not_bw(i32 %x) {\\n#0:\\n %ct = cttz i32 %x, 0\\n %cmp = icmp ne i32 %x, 0\\n %res = select i1 %cmp, i32 %ct, i32 123\\n ret i32 %res\\n}\\n=>\\ndefine i32 @test_cttz_not_bw(i32 %x) {\\n#0:\\n %ct = cttz i32 %x, 1\\n %#range_0_%ct = !range i32 %ct, i32 0, i32 33\\n %cmp.not = icmp eq i32 %x, 0\\n %res = select i1 %cmp.not, i32 123, i32 %#range_0_%ct\\n ret i32 %res\\n}\\nTransformation seems to be correct!\\n\\nSummary:\\n 1 correct transformations\\n 0 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n', 'opt_stderr': ''}}, {'file': 'llvm/test/Transforms/InstCombine/select-cmp-cttz-ctlz.ll', 'args': 'opt -passes=instcombine -S < %s', 'name': 'test_cttz_not_bw_noundef', 'body': 'define i32 @test_cttz_not_bw_noundef(i32 %x) {\\n %ct = tail call noundef i32 @llvm.cttz.i32(i32 %x, i1 false)\\n %cmp = icmp ne i32 %x, 0\\n %res = select i1 %cmp, i32 %ct, i32 123\\n ret i32 %res\\n}\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n', 'result': False, 'log': {'src': 'define i32 @test_cttz_not_bw_noundef(i32 %x) {\\n %ct = tail call noundef i32 @llvm.cttz.i32(i32 %x, i1 false)\\n %cmp = icmp ne i32 %x, 0\\n %res = select i1 %cmp, i32 %ct, i32 123\\n ret i32 %res\\n}\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n', 'tgt': '; ModuleID = \\'<stdin>\\'\\nsource_filename = \"<stdin>\"\\n\\ndefine i32 @test_cttz_not_bw_noundef(i32 %x) {\\n %ct = tail call noundef range(i32 0, 33) i32 @llvm.cttz.i32(i32 %x, i1 true)\\n %cmp.not = icmp eq i32 %x, 0\\n %res = select i1 %cmp.not, i32 123, i32 %ct\\n ret i32 %res\\n}\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n', 'log': \"\\n----------------------------------------\\ndefine i32 @test_cttz_not_bw_noundef(i32 %x) {\\n#0:\\n %ct = cttz i32 %x, 0\\n assume_welldefined i32 %ct\\n %cmp = icmp ne i32 %x, 0\\n %res = select i1 %cmp, i32 %ct, i32 123\\n ret i32 %res\\n}\\n=>\\ndefine i32 @test_cttz_not_bw_noundef(i32 %x) {\\n#0:\\n %ct = cttz i32 %x, 1\\n %#range_0_%ct = !range i32 %ct, i32 0, i32 33\\n assume_welldefined i32 %#range_0_%ct\\n %cmp.not = icmp eq i32 %x, 0\\n %res = select i1 %cmp.not, i32 123, i32 %#range_0_%ct\\n ret i32 %res\\n}\\nTransformation doesn't verify!\\n\\nERROR: Source is more defined than target\\n\\nExample:\\ni32 %x = #x00000000 (0)\\n\\nSource:\\ni32 %ct = #x00000020 (32)\\ni1 %cmp = #x0 (0)\\ni32 %res = #x0000007b (123)\\n\\nTarget:\\ni32 %ct = poison\\ni32 %#range_0_%ct = poison\\nvoid = UB triggered!\\n\\n\\nSummary:\\n 0 correct transformations\\n 1 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n\", 'opt_stderr': ''}}]\nPlease modify the following code in llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:foldSelectCttzCtlz to fix the bug:\n```\n IC.addToWorklist(II);\n return SelectArg;\n }\n\n // The ValueOnZero is not the bitwidth. But if the cttz/ctlz (and optional\n // zext/trunc) have one use (ending at the select), the cttz/ctlz result will\n // not be used if the input is zero. Relax to 'zero is poison' for that case.\n if (II->hasOneUse() && SelectArg->hasOneUse() &&\n !match(II->getArgOperand(1), m_One()))\n II->setArgOperand(1, ConstantInt::getTrue(II->getContext()));\n\n return nullptr;\n}\n\nstatic Value *canonicalizeSPF(ICmpInst &Cmp, Value *TrueVal, Value *FalseVal,\n InstCombinerImpl &IC) {\n Value *LHS, *RHS;\n // TODO: What to do with pointer min/max patterns?\n```\n"
40
- },
41
- {
42
- "role": "assistant",
43
- "content": "```cpp\n IC.addToWorklist(II);\n return SelectArg;\n }\n\n // The ValueOnZero is not the bitwidth. But if the cttz/ctlz (and optional\n // zext/trunc) have one use (ending at the select), the cttz/ctlz result will\n // not be used if the input is zero. Relax to 'zero is poison' for that case.\n if (II->hasOneUse() && SelectArg->hasOneUse() &&\n !match(II->getArgOperand(1), m_One())) {\n II->setArgOperand(1, ConstantInt::getTrue(II->getContext()));\n // Drop noundef attribute since the result may be poison now\n if (II->hasRetAttr(Attribute::NoUndef))\n II->removeRetAttr(Attribute::NoUndef);\n }\n\n return nullptr;\n}\n\nstatic Value *canonicalizeSPF(ICmpInst &Cmp, Value *TrueVal, Value *FalseVal,\n InstCombinerImpl &IC) {\n Value *LHS, *RHS;\n // TODO: What to do with pointer min/max patterns?\n```"
44
- }
45
- ]
46
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
examples/fixes/121432.json DELETED
@@ -1,70 +0,0 @@
1
- {
2
- "wall_time": 46.38868260383606,
3
- "knowledge": [
4
- [
5
- "base_model",
6
- "2023-12-31+0000"
7
- ],
8
- [
9
- "hint:bug_functions",
10
- "2025-01-01+0000"
11
- ],
12
- [
13
- "hint:components",
14
- "2025-01-01+0000"
15
- ],
16
- [
17
- "hint:issue",
18
- "2025-01-01+0000"
19
- ],
20
- [
21
- "hint:line_level_bug_locations",
22
- "2025-01-01+0000"
23
- ]
24
- ],
25
- "build_count": 5,
26
- "build_failure_count": 0,
27
- "fast_check_count": 1,
28
- "full_check_count": 4,
29
- "fast_check_pass": true,
30
- "full_check_pass": true,
31
- "patch": "diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp\nindex cdb2c11ef046..cf82e1c59bb2 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp\n@@ -2655,7 +2655,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {\n }\n case Intrinsic::copysign: {\n Value *Mag = II->getArgOperand(0), *Sign = II->getArgOperand(1);\n- if (std::optional<bool> KnownSignBit = computeKnownFPSignBit(\n+if (std::optional<bool> KnownSignBit = computeKnownFPSignBit(\n Sign, /*Depth=*/0, getSimplifyQuery().getWithInstruction(II))) {\n if (*KnownSignBit) {\n // If we know that the sign argument is negative, reduce to FNABS:\n@@ -2673,8 +2673,12 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {\n // Propagate sign argument through nested calls:\n // copysign Mag, (copysign ?, X) --> copysign Mag, X\n Value *X;\n- if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X))))\n- return replaceOperand(*II, 1, X);\n+ if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) {\n+ CallInst *NewCI = cast<CallInst>(replaceOperand(*II, 1, X));\n+ NewCI->copyIRFlags(II, /*IncludeWrapFlags=*/false);\n+ NewCI->andIRFlags(Sign);\n+ return NewCI;\n+ }\n \n // Clear sign-bit of constant magnitude:\n // copysign -MagC, X --> copysign MagC, X\n",
32
- "log": [
33
- {
34
- "role": "system",
35
- "content": "You are an LLVM maintainer.\nYou are fixing a middle-end bug in the LLVM project.\nPlease answer with the code directly. Do not include any additional information.\n"
36
- },
37
- {
38
- "role": "user",
39
- "content": "This is a miscompilation bug in InstCombine.\nIssue title: [InstCombine] FMF flags should not be propagated\nIssue body: Alive2: https://alive2.llvm.org/ce/z/ajCxTh\n```\ndefine float @src1(float noundef %x, float noundef %y, float noundef %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call nnan float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\ndefine float @tgt1(float noundef %x, float noundef %y, float noundef %z) {\n %r = call nnan float @llvm.copysign.f32(float %x, float %z)\n ret float %r\n}\n\ndefine float @src2(float noundef %x, float noundef %y, float noundef %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call ninf float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\ndefine float @tgt2(float noundef %x, float noundef %y, float noundef %z) {\n %r = call ninf float @llvm.copysign.f32(float %x, float %z)\n ret float %r\n}\n\ndefine float @src3(float noundef %x, float noundef %y, float noundef %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call nsz float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\ndefine float @tgt3(float noundef %x, float noundef %y, float noundef %z) {\n %r = call nsz float @llvm.copysign.f32(float %x, float %z)\n ret float %r\n}\n```\n\nDetailed information:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/copysign.ll\",\n \"args\": \"opt -S -passes=instcombine < %s\",\n \"name\": \"copysign_sign_arg_mixed\",\n \"body\": \"; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %s = call ninf nsz float @llvm.copysign.f32(float %y, float %z)\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %s)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"result\": false,\n \"log\": {\n \"src\": \"; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %s = call ninf nsz float @llvm.copysign.f32(float %y, float %z)\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %s)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"tgt\": \"; ModuleID = '<stdin>'\\nsource_filename = \\\"<stdin>\\\"\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %z)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"log\": \"\\n----------------------------------------\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n#0:\\n %s = copysign ninf nsz float %y, %z\\n %r = copysign nnan nsz float %x, %s\\n ret float %r\\n}\\n=>\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n#0:\\n %r = copysign nnan nsz float %x, %z\\n ret float %r\\n}\\nTransformation doesn't verify!\\n\\nERROR: Target is more poisonous than source\\n\\nExample:\\nfloat %x = #x00000000 (+0.0)\\nfloat %y = #x00000000 (+0.0)\\nfloat %z = #x7f800004 (SNaN)\\n\\nSource:\\nfloat %s = #x00000000 (+0.0)\\nfloat %r = #x00000000 (+0.0)\\n\\nTarget:\\nfloat %r = poison\\nSource value: #x00000000 (+0.0)\\nTarget value: poison\\n\\nSummary:\\n 0 correct transformations\\n 1 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n\",\n \"opt_stderr\": \"\"\n }\n}\nPlease modify the following code in llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp:InstCombinerImpl::visitCallInst to fix the bug:\n```\n if (std::optional<bool> KnownSignBit = computeKnownFPSignBit(\n Sign, /*Depth=*/0, getSimplifyQuery().getWithInstruction(II))) {\n if (*KnownSignBit) {\n // If we know that the sign argument is negative, reduce to FNABS:\n // copysign Mag, -Sign --> fneg (fabs Mag)\n Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);\n return replaceInstUsesWith(*II, Builder.CreateFNegFMF(Fabs, II));\n }\n\n // If we know that the sign argument is positive, reduce to FABS:\n // copysign Mag, +Sign --> fabs Mag\n Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);\n return replaceInstUsesWith(*II, Fabs);\n }\n\n // Propagate sign argument through nested calls:\n // copysign Mag, (copysign ?, X) --> copysign Mag, X\n Value *X;\n if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X))))\n return replaceOperand(*II, 1, X);\n\n // Clear sign-bit of constant magnitude:\n // copysign -MagC, X --> copysign MagC, X\n // TODO: Support constant folding for fabs\n const APFloat *MagC;\n if (match(Mag, m_APFloat(MagC)) && MagC->isNegative()) {\n APFloat PosMagC = *MagC;\n PosMagC.clearSign();\n return replaceOperand(*II, 0, ConstantFP::get(Mag->getType(), PosMagC));\n }\n\n // Peek through changes of magnitude's sign-bit. This call rewrites those:\n // copysign (fabs X), Sign --> copysign X, Sign\n // copysign (fneg X), Sign --> copysign X, Sign\n if (match(Mag, m_FAbs(m_Value(X))) || match(Mag, m_FNeg(m_Value(X))))\n return replaceOperand(*II, 0, X);\n\n break;\n```\n"
40
- },
41
- {
42
- "role": "assistant",
43
- "content": "```cpp\n if (std::optional<bool> KnownSignBit = computeKnownFPSignBit(\n Sign, /*Depth=*/0, getSimplifyQuery().getWithInstruction(II))) {\n if (*KnownSignBit) {\n // If we know that the sign argument is negative, reduce to FNABS:\n // copysign Mag, -Sign --> fneg (fabs Mag)\n Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);\n return replaceInstUsesWith(*II, Builder.CreateFNegFMF(Fabs, II));\n }\n\n // If we know that the sign argument is positive, reduce to FABS:\n // copysign Mag, +Sign --> fabs Mag\n Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);\n return replaceInstUsesWith(*II, Fabs);\n }\n\n // Propagate sign argument through nested calls:\n // copysign Mag, (copysign ?, X) --> copysign Mag, X\n Value *X;\n if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) {\n CallInst *NewCI = cast<CallInst>(replaceOperand(*II, 1, X));\n NewCI->copyFastMathFlags(II);\n return NewCI;\n }\n\n // Clear sign-bit of constant magnitude:\n // copysign -MagC, X --> copysign MagC, X\n // TODO: Support constant folding for fabs\n const APFloat *MagC;\n if (match(Mag, m_APFloat(MagC)) && MagC->isNegative()) {\n APFloat PosMagC = *MagC;\n PosMagC.clearSign();\n return replaceOperand(*II, 0, ConstantFP::get(Mag->getType(), PosMagC));\n }\n\n // Peek through changes of magnitude's sign-bit. This call rewrites those:\n // copysign (fabs X), Sign --> copysign X, Sign\n // copysign (fneg X), Sign --> copysign X, Sign\n if (match(Mag, m_FAbs(m_Value(X))) || match(Mag, m_FNeg(m_Value(X))))\n return replaceOperand(*II, 0, X);\n\n break;\n```"
44
- },
45
- {
46
- "role": "user",
47
- "content": "Feedback:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/copysign.ll\",\n \"args\": \"opt -S -passes=instcombine < %s\",\n \"name\": \"copysign_sign_arg_mixed\",\n \"body\": \"; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %s = call ninf nsz float @llvm.copysign.f32(float %y, float %z)\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %s)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"result\": false,\n \"log\": {\n \"src\": \"; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %s = call ninf nsz float @llvm.copysign.f32(float %y, float %z)\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %s)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"tgt\": \"; ModuleID = '<stdin>'\\nsource_filename = \\\"<stdin>\\\"\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %z)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"log\": \"\\n----------------------------------------\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n#0:\\n %s = copysign ninf nsz float %y, %z\\n %r = copysign nnan nsz float %x, %s\\n ret float %r\\n}\\n=>\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n#0:\\n %r = copysign nnan nsz float %x, %z\\n ret float %r\\n}\\nTransformation doesn't verify!\\n\\nERROR: Target is more poisonous than source\\n\\nExample:\\nfloat %x = #x00000000 (+0.0)\\nfloat %y = #x00000000 (+0.0)\\nfloat %z = #x7f800004 (SNaN)\\n\\nSource:\\nfloat %s = #x00000000 (+0.0)\\nfloat %r = #x00000000 (+0.0)\\n\\nTarget:\\nfloat %r = poison\\nSource value: #x00000000 (+0.0)\\nTarget value: poison\\n\\nSummary:\\n 0 correct transformations\\n 1 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n\",\n \"opt_stderr\": \"\"\n }\n}\nPlease adjust code according to the feedback. Do not include any additional information.\n"
48
- },
49
- {
50
- "role": "assistant",
51
- "content": "```cpp\n if (std::optional<bool> KnownSignBit = computeKnownFPSignBit(\n Sign, /*Depth=*/0, getSimplifyQuery().getWithInstruction(II))) {\n if (*KnownSignBit) {\n // If we know that the sign argument is negative, reduce to FNABS:\n // copysign Mag, -Sign --> fneg (fabs Mag)\n Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);\n return replaceInstUsesWith(*II, Builder.CreateFNegFMF(Fabs, II));\n }\n\n // If we know that the sign argument is positive, reduce to FABS:\n // copysign Mag, +Sign --> fabs Mag\n Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);\n return replaceInstUsesWith(*II, Fabs);\n }\n\n // Propagate sign argument through nested calls:\n // copysign Mag, (copysign ?, X) --> copysign Mag, X\n Value *X;\n if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) {\n CallInst *NewCI = cast<CallInst>(replaceOperand(*II, 1, X));\n NewCI->copyIRFlags(II);\n return NewCI;\n }\n\n // Clear sign-bit of constant magnitude:\n // copysign -MagC, X --> copysign MagC, X\n // TODO: Support constant folding for fabs\n const APFloat *MagC;\n if (match(Mag, m_APFloat(MagC)) && MagC->isNegative()) {\n APFloat PosMagC = *MagC;\n PosMagC.clearSign();\n return replaceOperand(*II, 0, ConstantFP::get(Mag->getType(), PosMagC));\n }\n\n // Peek through changes of magnitude's sign-bit. This call rewrites those:\n // copysign (fabs X), Sign --> copysign X, Sign\n // copysign (fneg X), Sign --> copysign X, Sign\n if (match(Mag, m_FAbs(m_Value(X))) || match(Mag, m_FNeg(m_Value(X))))\n return replaceOperand(*II, 0, X);\n\n break;\n```"
52
- },
53
- {
54
- "role": "user",
55
- "content": "Feedback:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/copysign.ll\",\n \"args\": \"opt -S -passes=instcombine < %s\",\n \"name\": \"copysign_sign_arg_mixed\",\n \"body\": \"; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %s = call ninf nsz float @llvm.copysign.f32(float %y, float %z)\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %s)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"result\": false,\n \"log\": {\n \"src\": \"; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %s = call ninf nsz float @llvm.copysign.f32(float %y, float %z)\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %s)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"tgt\": \"; ModuleID = '<stdin>'\\nsource_filename = \\\"<stdin>\\\"\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %z)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"log\": \"\\n----------------------------------------\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n#0:\\n %s = copysign ninf nsz float %y, %z\\n %r = copysign nnan nsz float %x, %s\\n ret float %r\\n}\\n=>\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n#0:\\n %r = copysign nnan nsz float %x, %z\\n ret float %r\\n}\\nTransformation doesn't verify!\\n\\nERROR: Target is more poisonous than source\\n\\nExample:\\nfloat %x = #x00000000 (+0.0)\\nfloat %y = #x00000000 (+0.0)\\nfloat %z = #x7f800004 (SNaN)\\n\\nSource:\\nfloat %s = #x00000000 (+0.0)\\nfloat %r = #x00000000 (+0.0)\\n\\nTarget:\\nfloat %r = poison\\nSource value: #x00000000 (+0.0)\\nTarget value: poison\\n\\nSummary:\\n 0 correct transformations\\n 1 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n\",\n \"opt_stderr\": \"\"\n }\n}\nPlease adjust code according to the feedback. Do not include any additional information.\n"
56
- },
57
- {
58
- "role": "assistant",
59
- "content": "```cpp\n if (std::optional<bool> KnownSignBit = computeKnownFPSignBit(\n Sign, /*Depth=*/0, getSimplifyQuery().getWithInstruction(II))) {\n if (*KnownSignBit) {\n // If we know that the sign argument is negative, reduce to FNABS:\n // copysign Mag, -Sign --> fneg (fabs Mag)\n Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);\n return replaceInstUsesWith(*II, Builder.CreateFNegFMF(Fabs, II));\n }\n\n // If we know that the sign argument is positive, reduce to FABS:\n // copysign Mag, +Sign --> fabs Mag\n Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);\n return replaceInstUsesWith(*II, Fabs);\n }\n\n // Propagate sign argument through nested calls:\n // copysign Mag, (copysign ?, X) --> copysign Mag, X\n Value *X;\n if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) {\n CallInst *NewCI = cast<CallInst>(replaceOperand(*II, 1, X));\n NewCI->copyIRFlags(II, /*IncludeWrapFlags=*/false);\n return NewCI;\n }\n\n // Clear sign-bit of constant magnitude:\n // copysign -MagC, X --> copysign MagC, X\n // TODO: Support constant folding for fabs\n const APFloat *MagC;\n if (match(Mag, m_APFloat(MagC)) && MagC->isNegative()) {\n APFloat PosMagC = *MagC;\n PosMagC.clearSign();\n return replaceOperand(*II, 0, ConstantFP::get(Mag->getType(), PosMagC));\n }\n\n // Peek through changes of magnitude's sign-bit. This call rewrites those:\n // copysign (fabs X), Sign --> copysign X, Sign\n // copysign (fneg X), Sign --> copysign X, Sign\n if (match(Mag, m_FAbs(m_Value(X))) || match(Mag, m_FNeg(m_Value(X))))\n return replaceOperand(*II, 0, X);\n\n break;\n```"
60
- },
61
- {
62
- "role": "user",
63
- "content": "Feedback:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/copysign.ll\",\n \"args\": \"opt -S -passes=instcombine < %s\",\n \"name\": \"copysign_sign_arg_mixed\",\n \"body\": \"; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %s = call ninf nsz float @llvm.copysign.f32(float %y, float %z)\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %s)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"result\": false,\n \"log\": {\n \"src\": \"; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %s = call ninf nsz float @llvm.copysign.f32(float %y, float %z)\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %s)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"tgt\": \"; ModuleID = '<stdin>'\\nsource_filename = \\\"<stdin>\\\"\\n\\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\\ndeclare float @llvm.copysign.f32(float, float) #0\\n\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %z)\\n ret float %r\\n}\\n\\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\\n\",\n \"log\": \"\\n----------------------------------------\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n#0:\\n %s = copysign ninf nsz float %y, %z\\n %r = copysign nnan nsz float %x, %s\\n ret float %r\\n}\\n=>\\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\\n#0:\\n %r = copysign nnan nsz float %x, %z\\n ret float %r\\n}\\nTransformation doesn't verify!\\n\\nERROR: Target is more poisonous than source\\n\\nExample:\\nfloat %x = #x00000000 (+0.0)\\nfloat %y = #x00000000 (+0.0)\\nfloat %z = #x7f800004 (SNaN)\\n\\nSource:\\nfloat %s = #x00000000 (+0.0)\\nfloat %r = #x00000000 (+0.0)\\n\\nTarget:\\nfloat %r = poison\\nSource value: #x00000000 (+0.0)\\nTarget value: poison\\n\\nSummary:\\n 0 correct transformations\\n 1 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n\",\n \"opt_stderr\": \"\"\n }\n}\nPlease adjust code according to the feedback. Do not include any additional information.\n"
64
- },
65
- {
66
- "role": "assistant",
67
- "content": "```cpp\n if (std::optional<bool> KnownSignBit = computeKnownFPSignBit(\n Sign, /*Depth=*/0, getSimplifyQuery().getWithInstruction(II))) {\n if (*KnownSignBit) {\n // If we know that the sign argument is negative, reduce to FNABS:\n // copysign Mag, -Sign --> fneg (fabs Mag)\n Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);\n return replaceInstUsesWith(*II, Builder.CreateFNegFMF(Fabs, II));\n }\n\n // If we know that the sign argument is positive, reduce to FABS:\n // copysign Mag, +Sign --> fabs Mag\n Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);\n return replaceInstUsesWith(*II, Fabs);\n }\n\n // Propagate sign argument through nested calls:\n // copysign Mag, (copysign ?, X) --> copysign Mag, X\n Value *X;\n if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) {\n CallInst *NewCI = cast<CallInst>(replaceOperand(*II, 1, X));\n NewCI->copyIRFlags(II, /*IncludeWrapFlags=*/false);\n NewCI->andIRFlags(Sign);\n return NewCI;\n }\n\n // Clear sign-bit of constant magnitude:\n // copysign -MagC, X --> copysign MagC, X\n // TODO: Support constant folding for fabs\n const APFloat *MagC;\n if (match(Mag, m_APFloat(MagC)) && MagC->isNegative()) {\n APFloat PosMagC = *MagC;\n PosMagC.clearSign();\n return replaceOperand(*II, 0, ConstantFP::get(Mag->getType(), PosMagC));\n }\n\n // Peek through changes of magnitude's sign-bit. This call rewrites those:\n // copysign (fabs X), Sign --> copysign X, Sign\n // copysign (fneg X), Sign --> copysign X, Sign\n if (match(Mag, m_FAbs(m_Value(X))) || match(Mag, m_FNeg(m_Value(X))))\n return replaceOperand(*II, 0, X);\n\n break;\n```"
68
- }
69
- ]
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
examples/fixes/121459.json DELETED
@@ -1,74 +0,0 @@
1
- {
2
- "wall_time": 85.64710140228271,
3
- "knowledge": [
4
- [
5
- "base_model",
6
- "2023-12-31+0000"
7
- ],
8
- [
9
- "hint:bug_functions",
10
- "2025-01-02+0000"
11
- ],
12
- [
13
- "hint:components",
14
- "2025-01-02+0000"
15
- ],
16
- [
17
- "hint:issue",
18
- "2025-01-02+0000"
19
- ],
20
- [
21
- "hint:line_level_bug_locations",
22
- "2025-01-02+0000"
23
- ]
24
- ],
25
- "build_count": 5,
26
- "build_failure_count": 2,
27
- "fast_check_count": 1,
28
- "full_check_count": 4,
29
- "fast_check_pass": false,
30
- "full_check_pass": false,
31
- "patch": "diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp\nindex 934156f04f7f..57ad53009408 100644\n--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp\n@@ -2764,7 +2764,7 @@ static bool shouldCanonicalizeGEPToPtrAdd(GetElementPtrInst &GEP) {\n return PtrOpGep && PtrOpGep->hasAllConstantIndices() &&\n any_of(GEP.indices(), [](Value *V) {\n const APInt *C;\n- return match(V, m_APInt(C)) && !C->isZero();\n+return match(V, m_APInt(C)) && !C->isZero();\n });\n }\n \n@@ -2862,9 +2862,22 @@ static Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN,\n PN->getNumOperands());\n }\n \n- for (auto &I : PN->operands())\n- NewPN->addIncoming(cast<GEPOperator>(I)->getOperand(DI),\n- PN->getIncomingBlock(I));\n+ for (auto &I : PN->operands()) {\n+ auto *GEPOp = cast<GEPOperator>(I);\n+ // Only propagate inbounds if all incoming GEPs are inbounds\n+ if (!GEPOp->isInBounds())\n+ NewGEP->setIsInBounds(false);\n+ // Only propagate nuw if all incoming GEPs are nuw\n+ if (!GEPOp->hasNoUnsignedWrap())\n+ NewGEP->setHasNoUnsignedWrap(false);\n+ NewPN->addIncoming(GEPOp->getOperand(DI), PN->getIncomingBlock(I));\n+ }\n+\n+ NewGEP->setOperand(DI, NewPN);\n+ }\n+\n+ return NewGEP;\n+}\n \n NewGEP->setOperand(DI, NewPN);\n }\n",
32
- "log": [
33
- {
34
- "role": "system",
35
- "content": "You are an LLVM maintainer.\nYou are fixing a middle-end bug in the LLVM project.\nPlease answer with the code directly. Do not include any additional information.\n"
36
- },
37
- {
38
- "role": "user",
39
- "content": "This is a miscompilation bug in InstCombine.\nIssue title: [InstCombine] GEPNoWrapFlags is propagated incorrectly\nIssue body: Alive2: https://alive2.llvm.org/ce/z/3ME7S7\n```\ndefine ptr @src(i1 %c, ptr %p) {\n br i1 %c, label %if, label %else\n\nif:\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\n br label %join\n\nelse:\n %gep2 = getelementptr i64, ptr %p, i64 2\n br label %join\n\njoin:\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = getelementptr i32, ptr %phi, i64 1\n ret ptr %gep\n}\n```\n```\n\n----------------------------------------\ndefine ptr @src(i1 %c, ptr %p) {\n#0:\n br i1 %c, label %if, label %else\n\nelse:\n %gep2 = gep ptr %p, 8 x i64 2\n br label %join\n\nif:\n %gep1 = gep inbounds ptr %p, 4 x i64 1\n br label %join\n\njoin:\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = gep ptr %phi, 4 x i64 1\n ret ptr %gep\n}\n=>\ndefine ptr @src(i1 %c, ptr %p) {\n#0:\n br i1 %c, label %if, label %else\n\nelse:\n br label %join\n\nif:\n br label %join\n\njoin:\n %#1 = phi i64 [ 4, %if ], [ 16, %else ]\n %#2 = gep inbounds nuw ptr %p, 1 x i64 %#1\n %gep = gep ptr %#2, 1 x i64 4\n ret ptr %gep\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\ni1 %c = #x0 (0)\nptr %p = null\n\nSource:\n >> Jump to %else\nptr %gep2 = pointer(non-local, block_id=0, offset=16) / Address=#x0000000000000010\n >> Jump to %join\nptr %phi = pointer(non-local, block_id=0, offset=16) / Address=#x0000000000000010\nptr %gep = pointer(non-local, block_id=0, offset=20) / Address=#x0000000000000014\n\nSOURCE MEMORY STATE\n===================\nNON-LOCAL BLOCKS:\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\nBlock 1 >\tsize: 0\talign: 1\talloc type: 0\talive: true\taddress: 1\n\nTarget:\n >> Jump to %else\n >> Jump to %join\ni64 %#1 = #x0000000000000010 (16)\nptr %#2 = poison\nptr %gep = poison\nSource value: pointer(non-local, block_id=0, offset=20) / Address=#x0000000000000014\nTarget value: poison\n\nSummary:\n 0 correct transformations\n 1 incorrect transformations\n 0 failed-to-prove transformations\n 0 Alive2 errors\n```\n\nDetailed information:\n[{'file': 'llvm/test/Transforms/InstCombine/opaque-ptr.ll', 'args': \"opt -S -passes='instcombine<no-verify-fixpoint>' < %s\", 'name': 'gep_of_phi_of_gep_different_type', 'body': 'define ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr i64, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'result': True, 'log': {'src': 'define ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr i64, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'tgt': '; ModuleID = \\'<stdin>\\'\\nsource_filename = \"<stdin>\"\\n\\ndefine ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n br label %join\\n\\nelse: ; preds = %0\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %1 = phi i64 [ 4, %if ], [ 16, %else ]\\n %2 = getelementptr i8, ptr %p, i64 %1\\n %gep = getelementptr i8, ptr %2, i64 4\\n ret ptr %gep\\n}\\n', 'log': '\\n----------------------------------------\\ndefine ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n %gep2 = gep ptr %p, 8 x i64 2\\n br label %join\\n\\nif:\\n %gep1 = gep ptr %p, 4 x i64 1\\n br label %join\\n\\njoin:\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = gep ptr %phi, 4 x i64 1\\n ret ptr %gep\\n}\\n=>\\ndefine ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n br label %join\\n\\nif:\\n br label %join\\n\\njoin:\\n %#1 = phi i64 [ 4, %if ], [ 16, %else ]\\n %#2 = gep ptr %p, 1 x i64 %#1\\n %gep = gep ptr %#2, 1 x i64 4\\n ret ptr %gep\\n}\\nTransformation seems to be correct!\\n\\nSummary:\\n 1 correct transformations\\n 0 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n', 'opt_stderr': ''}}, {'file': 'llvm/test/Transforms/InstCombine/opaque-ptr.ll', 'args': \"opt -S -passes='instcombine<no-verify-fixpoint>' < %s\", 'name': 'gep_of_phi_of_gep_flags2', 'body': 'define ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr nuw i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr nuw i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'result': True, 'log': {'src': 'define ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr nuw i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr nuw i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'tgt': '; ModuleID = \\'<stdin>\\'\\nsource_filename = \"<stdin>\"\\n\\ndefine ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n br label %join\\n\\nelse: ; preds = %0\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %1 = phi i64 [ 4, %if ], [ 8, %else ]\\n %2 = getelementptr nuw i8, ptr %p, i64 %1\\n %gep = getelementptr i8, ptr %2, i64 4\\n ret ptr %gep\\n}\\n', 'log': '\\n----------------------------------------\\ndefine ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n %gep2 = gep nuw ptr %p, 4 x i64 2\\n br label %join\\n\\nif:\\n %gep1 = gep nuw ptr %p, 4 x i64 1\\n br label %join\\n\\njoin:\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = gep ptr %phi, 4 x i64 1\\n ret ptr %gep\\n}\\n=>\\ndefine ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n br label %join\\n\\nif:\\n br label %join\\n\\njoin:\\n %#1 = phi i64 [ 4, %if ], [ 8, %else ]\\n %#2 = gep nuw ptr %p, 1 x i64 %#1\\n %gep = gep ptr %#2, 1 x i64 4\\n ret ptr %gep\\n}\\nTransformation seems to be correct!\\n\\nSummary:\\n 1 correct transformations\\n 0 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n', 'opt_stderr': ''}}, {'file': 'llvm/test/Transforms/InstCombine/opaque-ptr.ll', 'args': \"opt -S -passes='instcombine<no-verify-fixpoint>' < %s\", 'name': 'gep_of_phi_of_gep_flags1', 'body': 'define ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'result': False, 'log': {'src': 'define ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'tgt': '; ModuleID = \\'<stdin>\\'\\nsource_filename = \"<stdin>\"\\n\\ndefine ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n br label %join\\n\\nelse: ; preds = %0\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %1 = phi i64 [ 4, %if ], [ 8, %else ]\\n %2 = getelementptr inbounds nuw i8, ptr %p, i64 %1\\n %gep = getelementptr i8, ptr %2, i64 4\\n ret ptr %gep\\n}\\n', 'log': \"\\n----------------------------------------\\ndefine ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n %gep2 = gep ptr %p, 4 x i64 2\\n br label %join\\n\\nif:\\n %gep1 = gep inbounds ptr %p, 4 x i64 1\\n br label %join\\n\\njoin:\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = gep ptr %phi, 4 x i64 1\\n ret ptr %gep\\n}\\n=>\\ndefine ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n br label %join\\n\\nif:\\n br label %join\\n\\njoin:\\n %#1 = phi i64 [ 4, %if ], [ 8, %else ]\\n %#2 = gep inbounds nuw ptr %p, 1 x i64 %#1\\n %gep = gep ptr %#2, 1 x i64 4\\n ret ptr %gep\\n}\\nTransformation doesn't verify!\\n\\nERROR: Target is more poisonous than source\\n\\nExample:\\ni1 %c = #x0 (0)\\nptr %p = null\\n\\nSource:\\n >> Jump to %else\\nptr %gep2 = pointer(non-local, block_id=0, offset=8) / Address=#x0000000000000008\\n >> Jump to %join\\nptr %phi = pointer(non-local, block_id=0, offset=8) / Address=#x0000000000000008\\nptr %gep = pointer(non-local, block_id=0, offset=12) / Address=#x000000000000000c\\n\\nSOURCE MEMORY STATE\\n===================\\nNON-LOCAL BLOCKS:\\nBlock 0 >\\tsize: 0\\talign: 1\\talloc type: 0\\talive: false\\taddress: 0\\nBlock 1 >\\tsize: 0\\talign: 1\\talloc type: 0\\talive: true\\taddress: 1\\n\\nTarget:\\n >> Jump to %else\\n >> Jump to %join\\ni64 %#1 = #x0000000000000008 (8)\\nptr %#2 = poison\\nptr %gep = poison\\nSource value: pointer(non-local, block_id=0, offset=12) / Address=#x000000000000000c\\nTarget value: poison\\n\\nSummary:\\n 0 correct transformations\\n 1 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n\", 'opt_stderr': ''}}]\nPlease modify the following code in llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:foldGEPOfPhi to fix the bug:\n```\n return match(V, m_APInt(C)) && !C->isZero();\n });\n}\n\nstatic Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN,\n IRBuilderBase &Builder) {\n auto *Op1 = dyn_cast<GetElementPtrInst>(PN->getOperand(0));\n if (!Op1)\n return nullptr;\n\n // Don't fold a GEP into itself through a PHI node. This can only happen\n // through the back-edge of a loop. Folding a GEP into itself means that\n // the value of the previous iteration needs to be stored in the meantime,\n // thus requiring an additional register variable to be live, but not\n // actually achieving anything (the GEP still needs to be executed once per\n // loop iteration).\n if (Op1 == &GEP)\n return nullptr;\n\n int DI = -1;\n\n for (auto I = PN->op_begin()+1, E = PN->op_end(); I !=E; ++I) {\n auto *Op2 = dyn_cast<GetElementPtrInst>(*I);\n if (!Op2 || Op1->getNumOperands() != Op2->getNumOperands() ||\n Op1->getSourceElementType() != Op2->getSourceElementType())\n return nullptr;\n\n // As for Op1 above, don't try to fold a GEP into itself.\n if (Op2 == &GEP)\n return nullptr;\n\n // Keep track of the type as we walk the GEP.\n Type *CurTy = nullptr;\n\n for (unsigned J = 0, F = Op1->getNumOperands(); J != F; ++J) {\n if (Op1->getOperand(J)->getType() != Op2->getOperand(J)->getType())\n return nullptr;\n\n if (Op1->getOperand(J) != Op2->getOperand(J)) {\n if (DI == -1) {\n // We have not seen any differences yet in the GEPs feeding the\n // PHI yet, so we record this one if it is allowed to be a\n // variable.\n\n // The first two arguments can vary for any GEP, the rest have to be\n // static for struct slots\n if (J > 1) {\n assert(CurTy && \"No current type?\");\n if (CurTy->isStructTy())\n return nullptr;\n }\n\n DI = J;\n } else {\n // The GEP is different by more than one input. While this could be\n // extended to support GEPs that vary by more than one variable it\n // doesn't make sense since it greatly increases the complexity and\n // would result in an R+R+R addressing mode which no backend\n // directly supports and would need to be broken into several\n // simpler instructions anyway.\n return nullptr;\n }\n }\n\n // Sink down a layer of the type for the next iteration.\n if (J > 0) {\n if (J == 1) {\n CurTy = Op1->getSourceElementType();\n } else {\n CurTy =\n GetElementPtrInst::getTypeAtIndex(CurTy, Op1->getOperand(J));\n }\n }\n }\n }\n\n // If not all GEPs are identical we'll have to create a new PHI node.\n // Check that the old PHI node has only one use so that it will get\n // removed.\n if (DI != -1 && !PN->hasOneUse())\n return nullptr;\n\n auto *NewGEP = cast<GetElementPtrInst>(Op1->clone());\n if (DI == -1) {\n // All the GEPs feeding the PHI are identical. Clone one down into our\n // BB so that it can be merged with the current GEP.\n } else {\n // All the GEPs feeding the PHI differ at a single offset. Clone a GEP\n // into the current block so it can be merged, and create a new PHI to\n // set that index.\n PHINode *NewPN;\n {\n IRBuilderBase::InsertPointGuard Guard(Builder);\n Builder.SetInsertPoint(PN);\n NewPN = Builder.CreatePHI(Op1->getOperand(DI)->getType(),\n PN->getNumOperands());\n }\n\n for (auto &I : PN->operands())\n NewPN->addIncoming(cast<GEPOperator>(I)->getOperand(DI),\n PN->getIncomingBlock(I));\n```\n"
40
- },
41
- {
42
- "role": "assistant",
43
- "content": "```cpp\n return match(V, m_APInt(C)) && !C->isZero();\n });\n}\n\nstatic Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN,\n IRBuilderBase &Builder) {\n auto *Op1 = dyn_cast<GetElementPtrInst>(PN->getOperand(0));\n if (!Op1)\n return nullptr;\n\n // Don't fold a GEP into itself through a PHI node. This can only happen\n // through the back-edge of a loop. Folding a GEP into itself means that\n // the value of the previous iteration needs to be stored in the meantime,\n // thus requiring an additional register variable to be live, but not\n // actually achieving anything (the GEP still needs to be executed once per\n // loop iteration).\n if (Op1 == &GEP)\n return nullptr;\n\n int DI = -1;\n\n for (auto I = PN->op_begin()+1, E = PN->op_end(); I !=E; ++I) {\n auto *Op2 = dyn_cast<GetElementPtrInst>(*I);\n if (!Op2 || Op1->getNumOperands() != Op2->getNumOperands() ||\n Op1->getSourceElementType() != Op2->getSourceElementType())\n return nullptr;\n\n // As for Op1 above, don't try to fold a GEP into itself.\n if (Op2 == &GEP)\n return nullptr;\n\n // Keep track of the type as we walk the GEP.\n Type *CurTy = nullptr;\n\n for (unsigned J = 0, F = Op1->getNumOperands(); J != F; ++J) {\n if (Op1->getOperand(J)->getType() != Op2->getOperand(J)->getType())\n return nullptr;\n\n if (Op1->getOperand(J) != Op2->getOperand(J)) {\n if (DI == -1) {\n // We have not seen any differences yet in the GEPs feeding the\n // PHI yet, so we record this one if it is allowed to be a\n // variable.\n\n // The first two arguments can vary for any GEP, the rest have to be\n // static for struct slots\n if (J > 1) {\n assert(CurTy && \"No current type?\");\n if (CurTy->isStructTy())\n return nullptr;\n }\n\n DI = J;\n } else {\n // The GEP is different by more than one input. While this could be\n // extended to support GEPs that vary by more than one variable it\n // doesn't make sense since it greatly increases the complexity and\n // would result in an R+R+R addressing mode which no backend\n // directly supports and would need to be broken into several\n // simpler instructions anyway.\n return nullptr;\n }\n }\n\n // Sink down a layer of the type for the next iteration.\n if (J > 0) {\n if (J == 1) {\n CurTy = Op1->getSourceElementType();\n } else {\n CurTy =\n GetElementPtrInst::getTypeAtIndex(CurTy, Op1->getOperand(J));\n }\n }\n }\n }\n\n // If not all GEPs are identical we'll have to create a new PHI node.\n // Check that the old PHI node has only one use so that it will get\n // removed.\n if (DI != -1 && !PN->hasOneUse())\n return nullptr;\n\n auto *NewGEP = cast<GetElementPtrInst>(Op1->clone());\n if (DI == -1) {\n // All the GEPs feeding the PHI are identical. Clone one down into our\n // BB so that it can be merged with the current GEP.\n } else {\n // All the GEPs feeding the PHI differ at a single offset. Clone a GEP\n // into the current block so it can be merged, and create a new PHI to\n // set that index.\n PHINode *NewPN;\n {\n IRBuilderBase::InsertPointGuard Guard(Builder);\n Builder.SetInsertPoint(PN);\n NewPN = Builder.CreatePHI(Op1->getOperand(DI)->getType(),\n PN->getNumOperands());\n }\n\n for (auto &I : PN->operands()) {\n auto *GEPOp = cast<GEPOperator>(I);\n // Only propagate inbounds if all incoming GEPs are inbounds\n if (!GEPOp->isInBounds())\n NewGEP->setIsInBounds(false);\n NewPN->addIncoming(GEPOp->getOperand(DI), PN->getIncomingBlock(I));\n }\n```"
44
- },
45
- {
46
- "role": "user",
47
- "content": "Feedback:\n[{'file': 'llvm/test/Transforms/InstCombine/opaque-ptr.ll', 'args': \"opt -S -passes='instcombine<no-verify-fixpoint>' < %s\", 'name': 'gep_of_phi_of_gep_different_type', 'body': 'define ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr i64, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'result': True, 'log': {'src': 'define ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr i64, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'tgt': '; ModuleID = \\'<stdin>\\'\\nsource_filename = \"<stdin>\"\\n\\ndefine ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n br label %join\\n\\nelse: ; preds = %0\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %1 = phi i64 [ 4, %if ], [ 16, %else ]\\n %2 = getelementptr i8, ptr %p, i64 %1\\n %gep = getelementptr i8, ptr %2, i64 4\\n ret ptr %gep\\n}\\n', 'log': '\\n----------------------------------------\\ndefine ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n %gep2 = gep ptr %p, 8 x i64 2\\n br label %join\\n\\nif:\\n %gep1 = gep ptr %p, 4 x i64 1\\n br label %join\\n\\njoin:\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = gep ptr %phi, 4 x i64 1\\n ret ptr %gep\\n}\\n=>\\ndefine ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n br label %join\\n\\nif:\\n br label %join\\n\\njoin:\\n %#1 = phi i64 [ 4, %if ], [ 16, %else ]\\n %#2 = gep ptr %p, 1 x i64 %#1\\n %gep = gep ptr %#2, 1 x i64 4\\n ret ptr %gep\\n}\\nTransformation seems to be correct!\\n\\nSummary:\\n 1 correct transformations\\n 0 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n', 'opt_stderr': ''}}, {'file': 'llvm/test/Transforms/InstCombine/opaque-ptr.ll', 'args': \"opt -S -passes='instcombine<no-verify-fixpoint>' < %s\", 'name': 'gep_of_phi_of_gep_flags2', 'body': 'define ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr nuw i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr nuw i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'result': True, 'log': {'src': 'define ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr nuw i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr nuw i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'tgt': '; ModuleID = \\'<stdin>\\'\\nsource_filename = \"<stdin>\"\\n\\ndefine ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n br label %join\\n\\nelse: ; preds = %0\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %1 = phi i64 [ 4, %if ], [ 8, %else ]\\n %2 = getelementptr nuw i8, ptr %p, i64 %1\\n %gep = getelementptr i8, ptr %2, i64 4\\n ret ptr %gep\\n}\\n', 'log': '\\n----------------------------------------\\ndefine ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n %gep2 = gep nuw ptr %p, 4 x i64 2\\n br label %join\\n\\nif:\\n %gep1 = gep nuw ptr %p, 4 x i64 1\\n br label %join\\n\\njoin:\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = gep ptr %phi, 4 x i64 1\\n ret ptr %gep\\n}\\n=>\\ndefine ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n br label %join\\n\\nif:\\n br label %join\\n\\njoin:\\n %#1 = phi i64 [ 4, %if ], [ 8, %else ]\\n %#2 = gep nuw ptr %p, 1 x i64 %#1\\n %gep = gep ptr %#2, 1 x i64 4\\n ret ptr %gep\\n}\\nTransformation seems to be correct!\\n\\nSummary:\\n 1 correct transformations\\n 0 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n', 'opt_stderr': ''}}, {'file': 'llvm/test/Transforms/InstCombine/opaque-ptr.ll', 'args': \"opt -S -passes='instcombine<no-verify-fixpoint>' < %s\", 'name': 'gep_of_phi_of_gep_flags1', 'body': 'define ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'result': False, 'log': {'src': 'define ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'tgt': '; ModuleID = \\'<stdin>\\'\\nsource_filename = \"<stdin>\"\\n\\ndefine ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n br label %join\\n\\nelse: ; preds = %0\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %1 = phi i64 [ 4, %if ], [ 8, %else ]\\n %2 = getelementptr nusw nuw i8, ptr %p, i64 %1\\n %gep = getelementptr i8, ptr %2, i64 4\\n ret ptr %gep\\n}\\n', 'log': \"\\n----------------------------------------\\ndefine ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n %gep2 = gep ptr %p, 4 x i64 2\\n br label %join\\n\\nif:\\n %gep1 = gep inbounds ptr %p, 4 x i64 1\\n br label %join\\n\\njoin:\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = gep ptr %phi, 4 x i64 1\\n ret ptr %gep\\n}\\n=>\\ndefine ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n br label %join\\n\\nif:\\n br label %join\\n\\njoin:\\n %#1 = phi i64 [ 4, %if ], [ 8, %else ]\\n %#2 = gep nusw nuw ptr %p, 1 x i64 %#1\\n %gep = gep ptr %#2, 1 x i64 4\\n ret ptr %gep\\n}\\nTransformation doesn't verify!\\n\\nERROR: Target is more poisonous than source\\n\\nExample:\\ni1 %c = #x0 (0)\\nptr %p = pointer(non-local, block_id=1, offset=0) / Address=#xfffffffffffffff8\\n\\nSource:\\n >> Jump to %else\\nptr %gep2 = pointer(non-local, block_id=1, offset=8) / Address=#x0000000000000000\\n >> Jump to %join\\nptr %phi = pointer(non-local, block_id=1, offset=8) / Address=#x0000000000000000\\nptr %gep = pointer(non-local, block_id=1, offset=12) / Address=#x0000000000000004\\n\\nSOURCE MEMORY STATE\\n===================\\nNON-LOCAL BLOCKS:\\nBlock 0 >\\tsize: 0\\talign: 1\\talloc type: 0\\talive: false\\taddress: 0\\nBlock 1 >\\tsize: 0\\talign: 1\\talloc type: 0\\talive: true\\taddress: 18446744073709551608\\n\\nTarget:\\n >> Jump to %else\\n >> Jump to %join\\ni64 %#1 = #x0000000000000008 (8)\\nptr %#2 = poison\\nptr %gep = poison\\nSource value: pointer(non-local, block_id=1, offset=12) / Address=#x0000000000000004\\nTarget value: poison\\n\\nSummary:\\n 0 correct transformations\\n 1 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n\", 'opt_stderr': ''}}]\nPlease adjust code according to the feedback. Do not include any additional information.\n"
48
- },
49
- {
50
- "role": "assistant",
51
- "content": "```cpp\n return match(V, m_APInt(C)) && !C->isZero();\n });\n}\n\nstatic Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN,\n IRBuilderBase &Builder) {\n auto *Op1 = dyn_cast<GetElementPtrInst>(PN->getOperand(0));\n if (!Op1)\n return nullptr;\n\n // Don't fold a GEP into itself through a PHI node. This can only happen\n // through the back-edge of a loop. Folding a GEP into itself means that\n // the value of the previous iteration needs to be stored in the meantime,\n // thus requiring an additional register variable to be live, but not\n // actually achieving anything (the GEP still needs to be executed once per\n // loop iteration).\n if (Op1 == &GEP)\n return nullptr;\n\n int DI = -1;\n\n for (auto I = PN->op_begin()+1, E = PN->op_end(); I !=E; ++I) {\n auto *Op2 = dyn_cast<GetElementPtrInst>(*I);\n if (!Op2 || Op1->getNumOperands() != Op2->getNumOperands() ||\n Op1->getSourceElementType() != Op2->getSourceElementType())\n return nullptr;\n\n // As for Op1 above, don't try to fold a GEP into itself.\n if (Op2 == &GEP)\n return nullptr;\n\n // Keep track of the type as we walk the GEP.\n Type *CurTy = nullptr;\n\n for (unsigned J = 0, F = Op1->getNumOperands(); J != F; ++J) {\n if (Op1->getOperand(J)->getType() != Op2->getOperand(J)->getType())\n return nullptr;\n\n if (Op1->getOperand(J) != Op2->getOperand(J)) {\n if (DI == -1) {\n // We have not seen any differences yet in the GEPs feeding the\n // PHI yet, so we record this one if it is allowed to be a\n // variable.\n\n // The first two arguments can vary for any GEP, the rest have to be\n // static for struct slots\n if (J > 1) {\n assert(CurTy && \"No current type?\");\n if (CurTy->isStructTy())\n return nullptr;\n }\n\n DI = J;\n } else {\n // The GEP is different by more than one input. While this could be\n // extended to support GEPs that vary by more than one variable it\n // doesn't make sense since it greatly increases the complexity and\n // would result in an R+R+R addressing mode which no backend\n // directly supports and would need to be broken into several\n // simpler instructions anyway.\n return nullptr;\n }\n }\n\n // Sink down a layer of the type for the next iteration.\n if (J > 0) {\n if (J == 1) {\n CurTy = Op1->getSourceElementType();\n } else {\n CurTy =\n GetElementPtrInst::getTypeAtIndex(CurTy, Op1->getOperand(J));\n }\n }\n }\n }\n\n // If not all GEPs are identical we'll have to create a new PHI node.\n // Check that the old PHI node has only one use so that it will get\n // removed.\n if (DI != -1 && !PN->hasOneUse())\n return nullptr;\n\n auto *NewGEP = cast<GetElementPtrInst>(Op1->clone());\n if (DI == -1) {\n // All the GEPs feeding the PHI are identical. Clone one down into our\n // BB so that it can be merged with the current GEP.\n } else {\n // All the GEPs feeding the PHI differ at a single offset. Clone a GEP\n // into the current block so it can be merged, and create a new PHI to\n // set that index.\n PHINode *NewPN;\n {\n IRBuilderBase::InsertPointGuard Guard(Builder);\n Builder.SetInsertPoint(PN);\n NewPN = Builder.CreatePHI(Op1->getOperand(DI)->getType(),\n PN->getNumOperands());\n }\n\n for (auto &I : PN->operands()) {\n auto *GEPOp = cast<GEPOperator>(I);\n // Only propagate inbounds if all incoming GEPs are inbounds\n if (!GEPOp->isInBounds())\n NewGEP->setIsInBounds(false);\n // Only propagate nuw if all incoming GEPs are nuw\n if (!GEPOp->hasNoUnsignedWrap())\n NewGEP->setHasNoUnsignedWrap(false);\n // Only propagate nsw if all incoming GEPs are nsw\n if (!GEPOp->hasNoSignedWrap())\n NewGEP->setHasNoSignedWrap(false);\n NewPN->addIncoming(GEPOp->getOperand(DI), PN->getIncomingBlock(I));\n }\n```"
52
- },
53
- {
54
- "role": "user",
55
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (5.8s)\n-- Generating done (3.2s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/87] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/87] Linking CXX executable bin/llvm-config\n[3/87] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp: In function \u2018llvm::Instruction* foldGEPOfPhi(llvm::GetElementPtrInst&, llvm::PHINode*, llvm::IRBuilderBase&)\u2019:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2874:19: error: \u2018class llvm::GEPOperator\u2019 has no member named \u2018hasNoSignedWrap\u2019; did you mean \u2018hasNoUnsignedWrap\u2019?\n 2874 | if (!GEPOp->hasNoSignedWrap())\n | ^~~~~~~~~~~~~~~\n | hasNoUnsignedWrap\nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback. Do not include any additional information.\n"
56
- },
57
- {
58
- "role": "assistant",
59
- "content": "```cpp\n return match(V, m_APInt(C)) && !C->isZero();\n });\n}\n\nstatic Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN,\n IRBuilderBase &Builder) {\n auto *Op1 = dyn_cast<GetElementPtrInst>(PN->getOperand(0));\n if (!Op1)\n return nullptr;\n\n // Don't fold a GEP into itself through a PHI node. This can only happen\n // through the back-edge of a loop. Folding a GEP into itself means that\n // the value of the previous iteration needs to be stored in the meantime,\n // thus requiring an additional register variable to be live, but not\n // actually achieving anything (the GEP still needs to be executed once per\n // loop iteration).\n if (Op1 == &GEP)\n return nullptr;\n\n int DI = -1;\n\n for (auto I = PN->op_begin()+1, E = PN->op_end(); I !=E; ++I) {\n auto *Op2 = dyn_cast<GetElementPtrInst>(*I);\n if (!Op2 || Op1->getNumOperands() != Op2->getNumOperands() ||\n Op1->getSourceElementType() != Op2->getSourceElementType())\n return nullptr;\n\n // As for Op1 above, don't try to fold a GEP into itself.\n if (Op2 == &GEP)\n return nullptr;\n\n // Keep track of the type as we walk the GEP.\n Type *CurTy = nullptr;\n\n for (unsigned J = 0, F = Op1->getNumOperands(); J != F; ++J) {\n if (Op1->getOperand(J)->getType() != Op2->getOperand(J)->getType())\n return nullptr;\n\n if (Op1->getOperand(J) != Op2->getOperand(J)) {\n if (DI == -1) {\n // We have not seen any differences yet in the GEPs feeding the\n // PHI yet, so we record this one if it is allowed to be a\n // variable.\n\n // The first two arguments can vary for any GEP, the rest have to be\n // static for struct slots\n if (J > 1) {\n assert(CurTy && \"No current type?\");\n if (CurTy->isStructTy())\n return nullptr;\n }\n\n DI = J;\n } else {\n // The GEP is different by more than one input. While this could be\n // extended to support GEPs that vary by more than one variable it\n // doesn't make sense since it greatly increases the complexity and\n // would result in an R+R+R addressing mode which no backend\n // directly supports and would need to be broken into several\n // simpler instructions anyway.\n return nullptr;\n }\n }\n\n // Sink down a layer of the type for the next iteration.\n if (J > 0) {\n if (J == 1) {\n CurTy = Op1->getSourceElementType();\n } else {\n CurTy =\n GetElementPtrInst::getTypeAtIndex(CurTy, Op1->getOperand(J));\n }\n }\n }\n }\n\n // If not all GEPs are identical we'll have to create a new PHI node.\n // Check that the old PHI node has only one use so that it will get\n // removed.\n if (DI != -1 && !PN->hasOneUse())\n return nullptr;\n\n auto *NewGEP = cast<GetElementPtrInst>(Op1->clone());\n if (DI == -1) {\n // All the GEPs feeding the PHI are identical. Clone one down into our\n // BB so that it can be merged with the current GEP.\n } else {\n // All the GEPs feeding the PHI differ at a single offset. Clone a GEP\n // into the current block so it can be merged, and create a new PHI to\n // set that index.\n PHINode *NewPN;\n {\n IRBuilderBase::InsertPointGuard Guard(Builder);\n Builder.SetInsertPoint(PN);\n NewPN = Builder.CreatePHI(Op1->getOperand(DI)->getType(),\n PN->getNumOperands());\n }\n\n for (auto &I : PN->operands()) {\n auto *GEPOp = cast<GEPOperator>(I);\n // Only propagate inbounds if all incoming GEPs are inbounds\n if (!GEPOp->isInBounds())\n NewGEP->setIsInBounds(false);\n // Only propagate nuw if all incoming GEPs are nuw\n if (!GEPOp->hasNoUnsignedWrap())\n NewGEP->setHasNoUnsignedWrap(false);\n NewPN->addIncoming(GEPOp->getOperand(DI), PN->getIncomingBlock(I));\n }\n```"
60
- },
61
- {
62
- "role": "user",
63
- "content": "Feedback:\n[{'file': 'llvm/test/Transforms/InstCombine/opaque-ptr.ll', 'args': \"opt -S -passes='instcombine<no-verify-fixpoint>' < %s\", 'name': 'gep_of_phi_of_gep_different_type', 'body': 'define ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr i64, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'result': False, 'log': 'Command \\'[\\'/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt\\', \\'-S\\', \\'-passes=instcombine<no-verify-fixpoint>\\', \\'-\\']\\' died with <Signals.SIGABRT: 6>.\\n\\nopt: /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::TruncInst; From = llvm::Instruction]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"\\' failed.\\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\\nStack dump:\\n0.\\tProgram arguments: /data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt -S -passes=instcombine<no-verify-fixpoint> -\\n1.\\tRunning pass \"function(instcombine<max-iterations=1;no-verify-fixpoint>)\" on module \"<stdin>\"\\n2.\\tRunning pass \"instcombine<max-iterations=1;no-verify-fixpoint>\" on function \"gep_of_phi_of_gep_different_type\"\\n #0 0x00007ffff7eb679c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:727:3\\n #1 0x00007ffff7eb4234 llvm::sys::RunSignalHandlers() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Signals.cpp:105:20\\n #2 0x00007ffff7eb458e SignalHandler(int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1\\n #3 0x00007ffff7b3c090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\\n #4 0x00007ffff7b3c00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\\n #5 0x00007ffff7b1b859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\\n #6 0x00007ffff7b1b729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\\n #7 0x00007ffff7b1b729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\\n #8 0x00007ffff7b2cfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\\n #9 0x00007ffff20fed05 (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x213d05)\\n#10 0x00007ffff21001b6 (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x2151b6)\\n#11 0x00007ffff3344cb2 foldGEPOfPhi /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2872:37\\n#12 0x00007ffff3344cb2 llvm::InstCombinerImpl::visitGetElementPtrInst(llvm::GetElementPtrInst&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2973:39\\n#13 0x00007ffff33503f1 llvm::InstCombinerImpl::run() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5220:36\\n#14 0x00007ffff33513b3 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5538:5\\n#15 0x00007ffff3351d5b llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5600:3\\n#16 0x00007ffff4bc30d6 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#17 0x00007ffff2196bcc llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#18 0x00007ffff724e256 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#19 0x00007ffff21970f9 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/IR/PassManager.cpp:129:41\\n#20 0x00007ffff724ec16 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#21 0x00007ffff2195015 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#22 0x00007ffff7fa61a2 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:84:5\\n#23 0x00007ffff7fa61a2 llvm::SmallPtrSetImpl<llvm::AnalysisKey*>::~SmallPtrSetImpl() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:363:7\\n#24 0x00007ffff7fa61a2 llvm::SmallPtrSet<llvm::AnalysisKey*, 2u>::~SmallPtrSet() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:519:7\\n#25 0x00007ffff7fa61a2 llvm::PreservedAnalyses::~PreservedAnalyses() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/Analysis.h:111:7\\n#26 0x00007ffff7fa61a2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/NewPMDriver.cpp:541:10\\n#27 0x00007ffff7fb06af std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_data() const /usr/include/c++/10/bits/basic_string.h:195:28\\n#28 0x00007ffff7fb06af std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_is_local() const /usr/include/c++/10/bits/basic_string.h:230:23\\n#29 0x00007ffff7fb06af std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_dispose() /usr/include/c++/10/bits/basic_string.h:239:18\\n#30 0x00007ffff7fb06af std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/include/c++/10/bits/basic_string.h:671:19\\n#31 0x00007ffff7fb06af optMain /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/optdriver.cpp:710:28\\n#32 0x00007ffff7b1d083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\\n#33 0x000055555555509e _start (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt+0x109e)\\n'}, {'file': 'llvm/test/Transforms/InstCombine/opaque-ptr.ll', 'args': \"opt -S -passes='instcombine<no-verify-fixpoint>' < %s\", 'name': 'gep_of_phi_of_gep_flags2', 'body': 'define ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr nuw i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr nuw i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'result': True, 'log': {'src': 'define ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr nuw i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr nuw i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'tgt': '; ModuleID = \\'<stdin>\\'\\nsource_filename = \"<stdin>\"\\n\\ndefine ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n br label %join\\n\\nelse: ; preds = %0\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %1 = phi i64 [ 4, %if ], [ 8, %else ]\\n %2 = getelementptr nuw i8, ptr %p, i64 %1\\n %gep = getelementptr i8, ptr %2, i64 4\\n ret ptr %gep\\n}\\n', 'log': '\\n----------------------------------------\\ndefine ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n %gep2 = gep nuw ptr %p, 4 x i64 2\\n br label %join\\n\\nif:\\n %gep1 = gep nuw ptr %p, 4 x i64 1\\n br label %join\\n\\njoin:\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = gep ptr %phi, 4 x i64 1\\n ret ptr %gep\\n}\\n=>\\ndefine ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\\n#0:\\n br i1 %c, label %if, label %else\\n\\nelse:\\n br label %join\\n\\nif:\\n br label %join\\n\\njoin:\\n %#1 = phi i64 [ 4, %if ], [ 8, %else ]\\n %#2 = gep nuw ptr %p, 1 x i64 %#1\\n %gep = gep ptr %#2, 1 x i64 4\\n ret ptr %gep\\n}\\nTransformation seems to be correct!\\n\\nSummary:\\n 1 correct transformations\\n 0 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n', 'opt_stderr': ''}}, {'file': 'llvm/test/Transforms/InstCombine/opaque-ptr.ll', 'args': \"opt -S -passes='instcombine<no-verify-fixpoint>' < %s\", 'name': 'gep_of_phi_of_gep_flags1', 'body': 'define ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\\n br i1 %c, label %if, label %else\\n\\nif: ; preds = %0\\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\\n br label %join\\n\\nelse: ; preds = %0\\n %gep2 = getelementptr i32, ptr %p, i64 2\\n br label %join\\n\\njoin: ; preds = %else, %if\\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\\n %gep = getelementptr i32, ptr %phi, i64 1\\n ret ptr %gep\\n}\\n', 'result': False, 'log': 'Command \\'[\\'/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt\\', \\'-S\\', \\'-passes=instcombine<no-verify-fixpoint>\\', \\'-\\']\\' died with <Signals.SIGABRT: 6>.\\n\\nopt: /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::TruncInst; From = llvm::Instruction]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"\\' failed.\\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\\nStack dump:\\n0.\\tProgram arguments: /data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt -S -passes=instcombine<no-verify-fixpoint> -\\n1.\\tRunning pass \"function(instcombine<max-iterations=1;no-verify-fixpoint>)\" on module \"<stdin>\"\\n2.\\tRunning pass \"instcombine<max-iterations=1;no-verify-fixpoint>\" on function \"gep_of_phi_of_gep_flags1\"\\n #0 0x00007ffff7eb679c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:727:3\\n #1 0x00007ffff7eb4234 llvm::sys::RunSignalHandlers() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Signals.cpp:105:20\\n #2 0x00007ffff7eb458e SignalHandler(int) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1\\n #3 0x00007ffff7b3c090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\\n #4 0x00007ffff7b3c00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\\n #5 0x00007ffff7b1b859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\\n #6 0x00007ffff7b1b729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\\n #7 0x00007ffff7b1b729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\\n #8 0x00007ffff7b2cfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\\n #9 0x00007ffff20fed05 (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x213d05)\\n#10 0x00007ffff21001b6 (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x2151b6)\\n#11 0x00007ffff3344cb2 foldGEPOfPhi /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2872:37\\n#12 0x00007ffff3344cb2 llvm::InstCombinerImpl::visitGetElementPtrInst(llvm::GetElementPtrInst&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2973:39\\n#13 0x00007ffff33503f1 llvm::InstCombinerImpl::run() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5220:36\\n#14 0x00007ffff33513b3 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5538:5\\n#15 0x00007ffff3351d5b llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5600:3\\n#16 0x00007ffff4bc30d6 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#17 0x00007ffff2196bcc llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#18 0x00007ffff724e256 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#19 0x00007ffff21970f9 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/IR/PassManager.cpp:129:41\\n#20 0x00007ffff724ec16 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3\\n#21 0x00007ffff2195015 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18\\n#22 0x00007ffff7fa61a2 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:84:5\\n#23 0x00007ffff7fa61a2 llvm::SmallPtrSetImpl<llvm::AnalysisKey*>::~SmallPtrSetImpl() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:363:7\\n#24 0x00007ffff7fa61a2 llvm::SmallPtrSet<llvm::AnalysisKey*, 2u>::~SmallPtrSet() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:519:7\\n#25 0x00007ffff7fa61a2 llvm::PreservedAnalyses::~PreservedAnalyses() /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include/llvm/IR/Analysis.h:111:7\\n#26 0x00007ffff7fa61a2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/NewPMDriver.cpp:541:10\\n#27 0x00007ffff7fb06af std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_data() const /usr/include/c++/10/bits/basic_string.h:195:28\\n#28 0x00007ffff7fb06af std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_is_local() const /usr/include/c++/10/bits/basic_string.h:230:23\\n#29 0x00007ffff7fb06af std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_dispose() /usr/include/c++/10/bits/basic_string.h:239:18\\n#30 0x00007ffff7fb06af std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/include/c++/10/bits/basic_string.h:671:19\\n#31 0x00007ffff7fb06af optMain /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/tools/opt/optdriver.cpp:710:28\\n#32 0x00007ffff7b1d083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\\n#33 0x000055555555509e _start (/data/zyw/llvm-apr-benchmark/work/llvm-build/bin/opt+0x109e)\\n'}]\nPlease adjust code according to the feedback. Do not include any additional information.\n"
64
- },
65
- {
66
- "role": "assistant",
67
- "content": "```cpp\n return match(V, m_APInt(C)) && !C->isZero();\n });\n}\n\nstatic Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN,\n IRBuilderBase &Builder) {\n auto *Op1 = dyn_cast<GetElementPtrInst>(PN->getOperand(0));\n if (!Op1)\n return nullptr;\n\n // Don't fold a GEP into itself through a PHI node. This can only happen\n // through the back-edge of a loop. Folding a GEP into itself means that\n // the value of the previous iteration needs to be stored in the meantime,\n // thus requiring an additional register variable to be live, but not\n // actually achieving anything (the GEP still needs to be executed once per\n // loop iteration).\n if (Op1 == &GEP)\n return nullptr;\n\n int DI = -1;\n\n for (auto I = PN->op_begin()+1, E = PN->op_end(); I !=E; ++I) {\n auto *Op2 = dyn_cast<GetElementPtrInst>(*I);\n if (!Op2 || Op1->getNumOperands() != Op2->getNumOperands() ||\n Op1->getSourceElementType() != Op2->getSourceElementType())\n return nullptr;\n\n // As for Op1 above, don't try to fold a GEP into itself.\n if (Op2 == &GEP)\n return nullptr;\n\n // Keep track of the type as we walk the GEP.\n Type *CurTy = nullptr;\n\n for (unsigned J = 0, F = Op1->getNumOperands(); J != F; ++J) {\n if (Op1->getOperand(J)->getType() != Op2->getOperand(J)->getType())\n return nullptr;\n\n if (Op1->getOperand(J) != Op2->getOperand(J)) {\n if (DI == -1) {\n // We have not seen any differences yet in the GEPs feeding the\n // PHI yet, so we record this one if it is allowed to be a\n // variable.\n\n // The first two arguments can vary for any GEP, the rest have to be\n // static for struct slots\n if (J > 1) {\n assert(CurTy && \"No current type?\");\n if (CurTy->isStructTy())\n return nullptr;\n }\n\n DI = J;\n } else {\n // The GEP is different by more than one input. While this could be\n // extended to support GEPs that vary by more than one variable it\n // doesn't make sense since it greatly increases the complexity and\n // would result in an R+R+R addressing mode which no backend\n // directly supports and would need to be broken into several\n // simpler instructions anyway.\n return nullptr;\n }\n }\n\n // Sink down a layer of the type for the next iteration.\n if (J > 0) {\n if (J == 1) {\n CurTy = Op1->getSourceElementType();\n } else {\n CurTy =\n GetElementPtrInst::getTypeAtIndex(CurTy, Op1->getOperand(J));\n }\n }\n }\n }\n\n // If not all GEPs are identical we'll have to create a new PHI node.\n // Check that the old PHI node has only one use so that it will get\n // removed.\n if (DI != -1 && !PN->hasOneUse())\n return nullptr;\n\n auto *NewGEP = cast<GetElementPtrInst>(Op1->clone());\n if (DI == -1) {\n // All the GEPs feeding the PHI are identical. Clone one down into our\n // BB so that it can be merged with the current GEP.\n } else {\n // All the GEPs feeding the PHI differ at a single offset. Clone a GEP\n // into the current block so it can be merged, and create a new PHI to\n // set that index.\n PHINode *NewPN;\n {\n IRBuilderBase::InsertPointGuard Guard(Builder);\n Builder.SetInsertPoint(PN);\n NewPN = Builder.CreatePHI(Op1->getOperand(DI)->getType(),\n PN->getNumOperands());\n }\n\n for (auto &I : PN->operands()) {\n auto *GEPOp = cast<GEPOperator>(I);\n // Only propagate inbounds if all incoming GEPs are inbounds\n if (!GEPOp->isInBounds())\n NewGEP->setIsInBounds(false);\n // Only propagate nuw if all incoming GEPs are nuw\n if (!GEPOp->hasNoUnsignedWrap())\n NewGEP->setHasNoUnsignedWrap(false);\n NewPN->addIncoming(GEPOp->getOperand(DI), PN->getIncomingBlock(I));\n }\n\n NewGEP->setOperand(DI, NewPN);\n }\n\n return NewGEP;\n}\n```"
68
- },
69
- {
70
- "role": "user",
71
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (5.7s)\n-- Generating done (3.1s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/87] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/87] Linking CXX executable bin/llvm-config\n[3/87] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2882:5: error: \u2018NewGEP\u2019 does not name a type\n 2882 | NewGEP->setOperand(DI, NewPN);\n | ^~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2883:3: error: expected declaration before \u2018}\u2019 token\n 2883 | }\n | ^\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2885:3: error: \u2018NewGEP\u2019 does not name a type\n 2885 | NewGEP->insertBefore(*GEP.getParent(), GEP.getParent()->getFirstInsertionPt());\n | ^~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2886:3: error: expected unqualified-id before \u2018return\u2019\n 2886 | return NewGEP;\n | ^~~~~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2887:1: error: expected declaration before \u2018}\u2019 token\n 2887 | }\n | ^\nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback. Do not include any additional information.\n"
72
- }
73
- ]
74
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
examples/fixes/121581.json DELETED
@@ -1,79 +0,0 @@
1
- {
2
- "wall_time": 793.2528870105743,
3
- "knowledge": [
4
- [
5
- "base_model",
6
- "2023-12-31+0000"
7
- ],
8
- [
9
- "hint:bug_functions",
10
- "2025-01-03+0000"
11
- ],
12
- [
13
- "hint:components",
14
- "2025-01-03+0000"
15
- ],
16
- [
17
- "hint:issue",
18
- "2025-01-03+0000"
19
- ],
20
- [
21
- "hint:line_level_bug_locations",
22
- "2025-01-03+0000"
23
- ]
24
- ],
25
- "build_count": 5,
26
- "build_failure_count": 4,
27
- "fast_check_count": 1,
28
- "full_check_count": 4,
29
- "fast_check_pass": false,
30
- "full_check_pass": false,
31
- "patch": "diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\nindex d6fdade25559..4d056d0e57f4 100644\n--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n@@ -714,130 +714,7 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,\n // ((gep Ptr, OFFSET) cmp Ptr) ---> (OFFSET cmp 0).\n Value *Offset = EmitGEPOffset(GEPLHS);\n return NewICmp(GEPLHS->getNoWrapFlags(), Offset,\n- Constant::getNullValue(Offset->getType()));\n- }\n-\n- if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&\n- isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&\n- !NullPointerIsDefined(I.getFunction(),\n- RHS->getType()->getPointerAddressSpace())) {\n- // For most address spaces, an allocation can't be placed at null, but null\n- // itself is treated as a 0 size allocation in the in bounds rules. Thus,\n- // the only valid inbounds address derived from null, is null itself.\n- // Thus, we have four cases to consider:\n- // 1) Base == nullptr, Offset == 0 -> inbounds, null\n- // 2) Base == nullptr, Offset != 0 -> poison as the result is out of bounds\n- // 3) Base != nullptr, Offset == (-base) -> poison (crossing allocations)\n- // 4) Base != nullptr, Offset != (-base) -> nonnull (and possibly poison)\n- //\n- // (Note if we're indexing a type of size 0, that simply collapses into one\n- // of the buckets above.)\n- //\n- // In general, we're allowed to make values less poison (i.e. remove\n- // sources of full UB), so in this case, we just select between the two\n- // non-poison cases (1 and 4 above).\n- //\n- // For vectors, we apply the same reasoning on a per-lane basis.\n- auto *Base = GEPLHS->getPointerOperand();\n- if (GEPLHS->getType()->isVectorTy() && Base->getType()->isPointerTy()) {\n- auto EC = cast<VectorType>(GEPLHS->getType())->getElementCount();\n- Base = Builder.CreateVectorSplat(EC, Base);\n- }\n- return new ICmpInst(Cond, Base,\n- ConstantExpr::getPointerBitCastOrAddrSpaceCast(\n- cast<Constant>(RHS), Base->getType()));\n- } else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {\n- // If the base pointers are different, but the indices are the same, just\n- // compare the base pointer.\n- if (PtrBase != GEPRHS->getOperand(0)) {\n- bool IndicesTheSame =\n- GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&\n- GEPLHS->getPointerOperand()->getType() ==\n- GEPRHS->getPointerOperand()->getType() &&\n- GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType();\n- if (IndicesTheSame)\n- for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i)\n- if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {\n- IndicesTheSame = false;\n- break;\n- }\n-\n- // If all indices are the same, just compare the base pointers.\n- Type *BaseType = GEPLHS->getOperand(0)->getType();\n- if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n- return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n-\n- // If we're comparing GEPs with two base pointers that only differ in type\n- // and both GEPs have only constant indices or just one use, then fold\n- // the compare with the adjusted indices.\n- // FIXME: Support vector of pointers.\n- if (GEPLHS->isInBounds() && GEPRHS->isInBounds() &&\n- (GEPLHS->hasAllConstantIndices() || GEPLHS->hasOneUse()) &&\n- (GEPRHS->hasAllConstantIndices() || GEPRHS->hasOneUse()) &&\n- PtrBase->stripPointerCasts() ==\n- GEPRHS->getOperand(0)->stripPointerCasts() &&\n- !GEPLHS->getType()->isVectorTy()) {\n- Value *LOffset = EmitGEPOffset(GEPLHS);\n- Value *ROffset = EmitGEPOffset(GEPRHS);\n-\n- // If we looked through an addrspacecast between different sized address\n- // spaces, the LHS and RHS pointers are different sized\n- // integers. Truncate to the smaller one.\n- Type *LHSIndexTy = LOffset->getType();\n- Type *RHSIndexTy = ROffset->getType();\n- if (LHSIndexTy != RHSIndexTy) {\n- if (LHSIndexTy->getPrimitiveSizeInBits().getFixedValue() <\n- RHSIndexTy->getPrimitiveSizeInBits().getFixedValue()) {\n- ROffset = Builder.CreateTrunc(ROffset, LHSIndexTy);\n- } else\n- LOffset = Builder.CreateTrunc(LOffset, RHSIndexTy);\n- }\n-\n- Value *Cmp = Builder.CreateICmp(ICmpInst::getSignedPredicate(Cond),\n- LOffset, ROffset);\n- return replaceInstUsesWith(I, Cmp);\n- }\n-\n- // Otherwise, the base pointers are different and the indices are\n- // different. Try convert this to an indexed compare by looking through\n- // PHIs/casts.\n- return transformToIndexedCompare(GEPLHS, RHS, Cond, DL, *this);\n- }\n-\n- GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags() & GEPRHS->getNoWrapFlags();\n- if (GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&\n- GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType()) {\n- // If the GEPs only differ by one index, compare it.\n- unsigned NumDifferences = 0; // Keep track of # differences.\n- unsigned DiffOperand = 0; // The operand that differs.\n- for (unsigned i = 1, e = GEPRHS->getNumOperands(); i != e; ++i)\n- if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {\n- Type *LHSType = GEPLHS->getOperand(i)->getType();\n- Type *RHSType = GEPRHS->getOperand(i)->getType();\n- // FIXME: Better support for vector of pointers.\n- if (LHSType->getPrimitiveSizeInBits() !=\n- RHSType->getPrimitiveSizeInBits() ||\n- (GEPLHS->getType()->isVectorTy() &&\n- (!LHSType->isVectorTy() || !RHSType->isVectorTy()))) {\n- // Irreconcilable differences.\n- NumDifferences = 2;\n- break;\n- }\n-\n- if (NumDifferences++) break;\n- DiffOperand = i;\n- }\n \n- if (NumDifferences == 0) // SAME GEP?\n- return replaceInstUsesWith(I, // No comparison is needed here.\n- ConstantInt::get(I.getType(), ICmpInst::isTrueWhenEqual(Cond)));\n-\n- else if (NumDifferences == 1 && CanFold(NW)) {\n- Value *LHSV = GEPLHS->getOperand(DiffOperand);\n- Value *RHSV = GEPRHS->getOperand(DiffOperand);\n- return NewICmp(NW, LHSV, RHSV);\n- }\n- }\n \n if (CanFold(NW)) {\n // ((gep Ptr, OFFSET1) cmp (gep Ptr, OFFSET2) ---> (OFFSET1 cmp OFFSET2)\n",
32
- "log": {
33
- "model": "deepseek-reasoner",
34
- "messages": [
35
- {
36
- "role": "system",
37
- "content": "You are an LLVM maintainer.\nYou are fixing a middle-end bug in the LLVM project.\nPlease answer with the code directly. Do not include any additional information in the output.\nPlease answer with the complete code snippet (including the unmodified part) that replaces the original code. Do not answer with a diff.\n"
38
- },
39
- {
40
- "role": "user",
41
- "content": "This is a miscompilation bug in InstCombine.\nIssue title: [InstCombine] Incorrect fold of the comparison of GEPs\nIssue body: Alive2: https://alive2.llvm.org/ce/z/HRsqeW\n```\ndefine i1 @test(ptr %x, ptr %y) {\n %gep1 = getelementptr i8, ptr %x, i32 1\n %gep2 = getelementptr i8, ptr %y, i32 1\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n```\n```\n\n----------------------------------------\ndefine i1 @test(ptr %x, ptr %y) {\n#0:\n %gep1 = gep ptr %x, 1 x i32 1\n %gep2 = gep ptr %y, 1 x i32 1\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n=>\ndefine i1 @test(ptr %x, ptr %y) {\n#0:\n %cmp = icmp ult ptr %x, %y\n ret i1 %cmp\n}\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\nptr %x = pointer(non-local, block_id=0, offset=-1) / Address=#xf\nptr %y = null\n\nSource:\nptr %gep1 = null\nptr %gep2 = pointer(non-local, block_id=0, offset=1) / Address=#x1\ni1 %cmp = #x1 (1)\n\nSOURCE MEMORY STATE\n===================\nNON-LOCAL BLOCKS:\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\nBlock 1 >\tsize: 1\talign: 2\talloc type: 0\talive: true\taddress: 2\nBlock 2 >\tsize: 0\talign: 1\talloc type: 0\talive: true\taddress: 3\n\nTarget:\ni1 %cmp = #x0 (0)\nSource value: #x1 (1)\nTarget value: #x0 (0)\n\nSummary:\n 0 correct transformations\n 1 incorrect transformations\n 0 failed-to-prove transformations\n 0 Alive2 errors\n```\nDetailed information:\n{\n \"file\": \"llvm/test/Transforms/InstCombine/icmp-gep.ll\",\n \"args\": \"opt -passes=instcombine -S < %s\",\n \"name\": \"gep_diff_base_same_indices_nuw_nusw\",\n \"body\": \"target datalayout = \\\"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\\\"\\n\\ndefine i1 @gep_diff_base_same_indices_nuw_nusw(ptr %x, ptr %y, i64 %z) {\\n %gep1 = getelementptr nuw i8, ptr %x, i64 %z\\n %gep2 = getelementptr nusw i8, ptr %y, i64 %z\\n %cmp = icmp ult ptr %gep1, %gep2\\n ret i1 %cmp\\n}\\n\",\n \"result\": false,\n \"log\": {\n \"src\": \"target datalayout = \\\"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\\\"\\n\\ndefine i1 @gep_diff_base_same_indices_nuw_nusw(ptr %x, ptr %y, i64 %z) {\\n %gep1 = getelementptr nuw i8, ptr %x, i64 %z\\n %gep2 = getelementptr nusw i8, ptr %y, i64 %z\\n %cmp = icmp ult ptr %gep1, %gep2\\n ret i1 %cmp\\n}\\n\",\n \"tgt\": \"; ModuleID = '<stdin>'\\nsource_filename = \\\"<stdin>\\\"\\ntarget datalayout = \\\"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\\\"\\n\\ndefine i1 @gep_diff_base_same_indices_nuw_nusw(ptr %x, ptr %y, i64 %z) {\\n %cmp = icmp ult ptr %x, %y\\n ret i1 %cmp\\n}\\n\",\n \"log\": \"\\n----------------------------------------\\ndefine i1 @gep_diff_base_same_indices_nuw_nusw(ptr %x, ptr %y, i64 %z) {\\n#0:\\n %gep1 = gep nuw ptr %x, 1 x i64 %z\\n %gep2 = gep nusw ptr %y, 1 x i64 %z\\n %cmp = icmp ult ptr %gep1, %gep2\\n ret i1 %cmp\\n}\\n=>\\ndefine i1 @gep_diff_base_same_indices_nuw_nusw(ptr %x, ptr %y, i64 %z) {\\n#0:\\n %cmp = icmp ult ptr %x, %y\\n ret i1 %cmp\\n}\\nTransformation doesn't verify!\\n\\nERROR: Value mismatch\\n\\nExample:\\nptr %x = null\\nptr %y = pointer(non-local, block_id=0, offset=8) / Address=#x0000000000000008\\ni64 %z = #xfffffffffffffff8 (18446744073709551608, -8)\\n\\nSource:\\nptr %gep1 = pointer(non-local, block_id=0, offset=-8) / Address=#xfffffffffffffff8\\nptr %gep2 = null\\ni1 %cmp = #x0 (0)\\n\\nSOURCE MEMORY STATE\\n===================\\nNON-LOCAL BLOCKS:\\nBlock 0 >\\tsize: 0\\talign: 1\\talloc type: 0\\talive: false\\taddress: 0\\nBlock 1 >\\tsize: 0\\talign: 1\\talloc type: 0\\talive: true\\taddress: 1\\nBlock 2 >\\tsize: 1198596317155164250\\talign: 8\\talloc type: 0\\talive: true\\taddress: 8\\n\\nTarget:\\ni1 %cmp = #x1 (1)\\nSource value: #x0 (0)\\nTarget value: #x1 (1)\\n\\nSummary:\\n 0 correct transformations\\n 1 incorrect transformations\\n 0 failed-to-prove transformations\\n 0 Alive2 errors\\n\",\n \"opt_stderr\": \"\"\n }\n}\nPlease modify the following code in llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:InstCombinerImpl::foldGEPICmp to fix the bug:\n```cpp\n Constant::getNullValue(Offset->getType()));\n }\n\n if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&\n isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&\n !NullPointerIsDefined(I.getFunction(),\n RHS->getType()->getPointerAddressSpace())) {\n // For most address spaces, an allocation can't be placed at null, but null\n // itself is treated as a 0 size allocation in the in bounds rules. Thus,\n // the only valid inbounds address derived from null, is null itself.\n // Thus, we have four cases to consider:\n // 1) Base == nullptr, Offset == 0 -> inbounds, null\n // 2) Base == nullptr, Offset != 0 -> poison as the result is out of bounds\n // 3) Base != nullptr, Offset == (-base) -> poison (crossing allocations)\n // 4) Base != nullptr, Offset != (-base) -> nonnull (and possibly poison)\n //\n // (Note if we're indexing a type of size 0, that simply collapses into one\n // of the buckets above.)\n //\n // In general, we're allowed to make values less poison (i.e. remove\n // sources of full UB), so in this case, we just select between the two\n // non-poison cases (1 and 4 above).\n //\n // For vectors, we apply the same reasoning on a per-lane basis.\n auto *Base = GEPLHS->getPointerOperand();\n if (GEPLHS->getType()->isVectorTy() && Base->getType()->isPointerTy()) {\n auto EC = cast<VectorType>(GEPLHS->getType())->getElementCount();\n Base = Builder.CreateVectorSplat(EC, Base);\n }\n return new ICmpInst(Cond, Base,\n ConstantExpr::getPointerBitCastOrAddrSpaceCast(\n cast<Constant>(RHS), Base->getType()));\n } else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {\n // If the base pointers are different, but the indices are the same, just\n // compare the base pointer.\n if (PtrBase != GEPRHS->getOperand(0)) {\n bool IndicesTheSame =\n GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&\n GEPLHS->getPointerOperand()->getType() ==\n GEPRHS->getPointerOperand()->getType() &&\n GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType();\n if (IndicesTheSame)\n for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i)\n if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {\n IndicesTheSame = false;\n break;\n }\n\n // If all indices are the same, just compare the base pointers.\n Type *BaseType = GEPLHS->getOperand(0)->getType();\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\n // If we're comparing GEPs with two base pointers that only differ in type\n // and both GEPs have only constant indices or just one use, then fold\n // the compare with the adjusted indices.\n // FIXME: Support vector of pointers.\n if (GEPLHS->isInBounds() && GEPRHS->isInBounds() &&\n (GEPLHS->hasAllConstantIndices() || GEPLHS->hasOneUse()) &&\n (GEPRHS->hasAllConstantIndices() || GEPRHS->hasOneUse()) &&\n PtrBase->stripPointerCasts() ==\n GEPRHS->getOperand(0)->stripPointerCasts() &&\n !GEPLHS->getType()->isVectorTy()) {\n Value *LOffset = EmitGEPOffset(GEPLHS);\n Value *ROffset = EmitGEPOffset(GEPRHS);\n\n // If we looked through an addrspacecast between different sized address\n // spaces, the LHS and RHS pointers are different sized\n // integers. Truncate to the smaller one.\n Type *LHSIndexTy = LOffset->getType();\n Type *RHSIndexTy = ROffset->getType();\n if (LHSIndexTy != RHSIndexTy) {\n if (LHSIndexTy->getPrimitiveSizeInBits().getFixedValue() <\n RHSIndexTy->getPrimitiveSizeInBits().getFixedValue()) {\n ROffset = Builder.CreateTrunc(ROffset, LHSIndexTy);\n } else\n LOffset = Builder.CreateTrunc(LOffset, RHSIndexTy);\n }\n\n Value *Cmp = Builder.CreateICmp(ICmpInst::getSignedPredicate(Cond),\n LOffset, ROffset);\n return replaceInstUsesWith(I, Cmp);\n }\n\n // Otherwise, the base pointers are different and the indices are\n // different. Try convert this to an indexed compare by looking through\n // PHIs/casts.\n return transformToIndexedCompare(GEPLHS, RHS, Cond, DL, *this);\n }\n\n GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags() & GEPRHS->getNoWrapFlags();\n if (GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&\n GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType()) {\n // If the GEPs only differ by one index, compare it.\n unsigned NumDifferences = 0; // Keep track of # differences.\n unsigned DiffOperand = 0; // The operand that differs.\n for (unsigned i = 1, e = GEPRHS->getNumOperands(); i != e; ++i)\n if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {\n Type *LHSType = GEPLHS->getOperand(i)->getType();\n Type *RHSType = GEPRHS->getOperand(i)->getType();\n // FIXME: Better support for vector of pointers.\n if (LHSType->getPrimitiveSizeInBits() !=\n RHSType->getPrimitiveSizeInBits() ||\n (GEPLHS->getType()->isVectorTy() &&\n (!LHSType->isVectorTy() || !RHSType->isVectorTy()))) {\n // Irreconcilable differences.\n NumDifferences = 2;\n break;\n }\n\n if (NumDifferences++) break;\n DiffOperand = i;\n }\n\n if (NumDifferences == 0) // SAME GEP?\n return replaceInstUsesWith(I, // No comparison is needed here.\n ConstantInt::get(I.getType(), ICmpInst::isTrueWhenEqual(Cond)));\n\n else if (NumDifferences == 1 && CanFold(NW)) {\n Value *LHSV = GEPLHS->getOperand(DiffOperand);\n Value *RHSV = GEPRHS->getOperand(DiffOperand);\n return NewICmp(NW, LHSV, RHSV);\n }\n }\n```\n\nPlease answer with the code directly. Do not include any additional information in the output.\nPlease answer with the complete code snippet (including the unmodified part) that replaces the original code. Do not answer with a diff.\nPlease make sure the answer includes the prefix:\n```cpp\n Constant::getNullValue(Offset->getType()));\n }\n\n if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&\n isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&\n```\nand the suffix:\n```cpp\n Value *LHSV = GEPLHS->getOperand(DiffOperand);\n Value *RHSV = GEPRHS->getOperand(DiffOperand);\n return NewICmp(NW, LHSV, RHSV);\n }\n }\n```\n"
42
- },
43
- {
44
- "role": "assistant",
45
- "content": "```cpp\n Constant::getNullValue(Offset->getType()));\n }\n\n if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&\n isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&\n !NullPointerIsDefined(I.getFunction(),\n RHS->getType()->getPointerAddressSpace())) {\n // For most address spaces, an allocation can't be placed at null, but null\n // itself is treated as a 0 size allocation in the in bounds rules. Thus,\n // the only valid inbounds address derived from null, is null itself.\n // Thus, we have four cases to consider:\n // 1) Base == nullptr, Offset == 0 -> inbounds, null\n // 2) Base == nullptr, Offset != 0 -> poison as the result is out of bounds\n // 3) Base != nullptr, Offset == (-base) -> poison (crossing allocations)\n // 4) Base != nullptr, Offset != (-base) -> nonnull (and possibly poison)\n //\n // (Note if we're indexing a type of size 0, that simply collapses into one\n // of the buckets above.)\n //\n // In general, we're allowed to make values less poison (i.e. remove\n // sources of full UB), so in this case, we just select between the two\n // non-poison cases (1 and 4 above).\n //\n // For vectors, we apply the same reasoning on a per-lane basis.\n auto *Base = GEPLHS->getPointerOperand();\n if (GEPLHS->getType()->isVectorTy() && Base->getType()->isPointerTy()) {\n auto EC = cast<VectorType>(GEPLHS->getType())->getElementCount();\n Base = Builder.CreateVectorSplat(EC, Base);\n }\n return new ICmpInst(Cond, Base,\n ConstantExpr::getPointerBitCastOrAddrSpaceCast(\n cast<Constant>(RHS), Base->getType()));\n } else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {\n // If the base pointers are different, but the indices are the same, just\n // compare the base pointer.\n if (PtrBase != GEPRHS->getOperand(0)) {\n bool IndicesTheSame =\n GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&\n GEPLHS->getPointerOperand()->getType() ==\n GEPRHS->getPointerOperand()->getType() &&\n GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType();\n if (IndicesTheSame)\n for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i)\n if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {\n IndicesTheSame = false;\n break;\n }\n\n // If all indices are the same, just compare the base pointers.\n Type *BaseType = GEPLHS->getOperand(0)->getType();\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType()) {\n if (ICmpInst::isEquality(Cond)) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n } else if (ICmpInst::isUnsigned(Cond) &&\n GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap()) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n } else if (ICmpInst::isSigned(Cond) &&\n GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap()) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n }\n }\n\n // If we're comparing GEPs with two base pointers that only differ in type\n // and both GEPs have only constant indices or just one use, then fold\n // the compare with the adjusted indices.\n // FIXME: Support vector of pointers.\n if (GEPLHS->isInBounds() && GEPRHS->isInBounds() &&\n (GEPLHS->hasAllConstantIndices() || GEPLHS->hasOneUse()) &&\n (GEPRHS->hasAllConstantIndices() || GEPRHS->hasOneUse()) &&\n PtrBase->stripPointerCasts() ==\n GEPRHS->getOperand(0)->stripPointerCasts() &&\n !GEPLHS->getType()->isVectorTy()) {\n Value *LOffset = EmitGEPOffset(GEPLHS);\n Value *ROffset = EmitGEPOffset(GEPRHS);\n\n // If we looked through an addrspacecast between different sized address\n // spaces, the LHS and RHS pointers are different sized\n // integers. Truncate to the smaller one.\n Type *LHSIndexTy = LOffset->getType();\n Type *RHSIndexTy = ROffset->getType();\n if (LHSIndexTy != RHSIndexTy) {\n if (LHSIndexTy->getPrimitiveSizeInBits().getFixedValue() <\n RHSIndexTy->getPrimitiveSizeInBits().getFixedValue()) {\n ROffset = Builder.CreateTrunc(ROffset, LHSIndexTy);\n } else\n LOffset = Builder.CreateTrunc(LOffset, RHSIndexTy);\n }\n\n Value *Cmp = Builder.CreateICmp(ICmpInst::getSignedPredicate(Cond),\n LOffset, ROffset);\n return replaceInstUsesWith(I, Cmp);\n }\n\n // Otherwise, the base pointers are different and the indices are\n // different. Try convert this to an indexed compare by looking through\n // PHIs/casts.\n return transformToIndexedCompare(GEPLHS, RHS, Cond, DL, *this);\n }\n\n GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags() & GEPRHS->getNoWrapFlags();\n if (GEPLHS->getNumOperands() == GEPRHS->getNumOperandss() &&\n GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType()) {\n // If the GEPs only differ by one index, compare it.\n unsigned NumDifferences = 0; // Keep track of # differences.\n unsigned DiffOperand = 0; // The operand that differs.\n for (unsigned i = 1, e = GEPRHS->getNumOperands(); i != e; ++i)\n if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {\n Type *LHSType = GEPLHS->getOperand(i)->getType();\n Type *RHSType = GEPRHS->getOperand(i)->getType();\n // FIXME: Better support for vector of pointers.\n if (LHSType->getPrimitiveSizeInBits() !=\n RHSType->getPrimitiveSizeInBits() ||\n (GEPLHS->getType()->isVectorTy() &&\n (!LHSType->isVectorTy() || !RHSType->isVectorTy()))) {\n // Irreconcilable differences.\n NumDifferences = 2;\n break;\n }\n\n if (NumDifferences++) break;\n DiffOperand = i;\n }\n\n if (NumDifferences == 0) // SAME GEP?\n return replaceInstUsesWith(I, // No comparison is needed here.\n ConstantInt::get(I.getType(), ICmpInst::isTrueWhenEqual(Cond)));\n\n else if (NumDifferences == 1 && CanFold(NW)) {\n Value *LHSV = GEPLHS->getOperand(DiffOperand);\n Value *RHSV = GEPRHS->getOperand(DiffOperand);\n return NewICmp(NW, LHSV, RHSV);\n }\n }\n```",
46
- "reasoning_content": "Okay, let's see. The problem here is that InstCombine is incorrectly folding a comparison of two GEPs with the same indices but different base pointers. The test case shows that when the GEPs add 1 to their respective bases, the comparison is being transformed to just compare the original bases. But this isn't always valid because the GEPs could wrap around, making the comparison of the original bases incorrect.\n\nLooking at the code in InstCombineCompares.cpp, specifically the foldGEPICmp function. The part that handles when the base pointers are different but the indices are the same. The code checks if all indices are the same and then replaces the GEP comparison with a comparison of the base pointers. But this transformation is unsafe when the GEPs might wrap, even if they have the same indices.\n\nThe issue arises because when the GEPs have inbounds or no-wrap flags, but in the test case, one GEP uses nuw and the other nusw. The existing code might not properly account for these flags, leading to an incorrect fold.\n\nIn the code, after checking if IndicesTheSame, it proceeds to compare the base pointers. But this is only valid if the GEPs don't wrap. So, we need to check if both GEPs have no-wrap flags that ensure that the offset doesn't cause wrapping. If either GEP could wrap, then comparing the bases directly isn't safe.\n\nSo, the fix is to add a check that both GEPs have no-wrap flags (either nuw or nsw, depending on the context) before allowing the transformation to compare the base pointers. If either GEP could wrap, then the indices being the same doesn't guarantee that the comparison of the GEPs is equivalent to the comparison of the bases.\n\nLooking at the code snippet provided, the relevant part is where it says:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nThis is where the code replaces the GEP comparison with the base pointer comparison. We need to modify this condition to only perform this replacement if both GEPs have no-wrap flags that prevent wrapping. Since the GEPs are being added with the same indices, we need to ensure that adding the indices to both bases doesn't change the order. For this, both GEPs must have both nuw and nusw (now called nsw for pointers) flags. Wait, actually, in LLVM, pointer GEPs can have inbounds, but nuw and nsw are separate. For pointers, the no-wrap flags might not be sufficient to ensure that the offset doesn't affect the comparison.\n\nWait, the problem in the test case is when one GEP is nuw and the other is nusw. The existing code allows the fold even if the GEPs have different no-wrap flags, which is incorrect. So, the fix is to require that both GEPs have the same no-wrap flags that prevent the offset from affecting the comparison. Alternatively, perhaps we should only allow the fold if both GEPs are inbounds, but that's not enough. Alternatively, we need to check that the addition of the indices doesn't affect the ordering between the two pointers. That might be complex.\n\nBut according to the Alive2 example, when the GEPs have different no-wrap flags, the fold is invalid. So, the code should not perform the transformation unless both GEPs have the necessary no-wrap flags. So, in the code, when checking IndicesTheSame, we should also check that both GEPs have the appropriate no-wrap flags to ensure that the offset doesn't wrap, thus making the comparison of the GEPs equivalent to the bases.\n\nIn the code, the line that performs the replacement is:\n\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nSo, before doing this, we need to add a check that both GEPLHS and GEPRHS have the necessary no-wrap flags. But what exactly are the necessary flags?\n\nThe original test case has one GEP with nuw and the other with nusw. The problem is that when the base pointers are such that adding the offset wraps in one direction but not the other. For example, if one GEP is nuw (no unsigned wrap) and the other is nusw (no signed wrap, which for pointers is the same as no signed wrap in the offset calculation). But comparing the GEPs could result in a different outcome than comparing the bases when the offsets cause wrapping.\n\nTherefore, the fold is only valid if both GEPs have both nuw and nusw (nsw) flags, or if their flags are sufficient to prevent any wrapping that could affect the comparison. Alternatively, the fold is safe only if the addition of the indices doesn't change the relative order of the base pointers.\n\nAlternatively, maybe the code should only perform this fold if the indices are non-negative, but that's not tracked in the IR.\n\nAlternatively, the code should check that both GEPs are inbounds and have no-wrap flags that ensure the offset doesn't affect the comparison. But how to determine that?\n\nWait, in the Alive2 example, the transformation is invalid because when the GEPs are added, the base pointers' offsets cross a boundary (like from -1 to 0 when adding 1). So, comparing the GEPs would give a different result than comparing the bases. Thus, the fold is incorrect unless adding the same offset to both bases doesn't change the comparison result.\n\nThis can only be guaranteed if the offset is such that the addition doesn't wrap in either direction. So, the GEPs must have both nuw and nsw flags, ensuring that the offset addition doesn't wrap. Alternatively, if the pointers are in the same object, but that's not something the compiler can know.\n\nSo, the fix is to only perform the fold if both GEPs have both nuw and nsw flags. But how to check that?\n\nLooking at the code, the current code doesn't check any flags here. So, adding a check for both GEPs having no-wrap flags (nuw and nsw) would prevent the incorrect fold.\n\nBut in the existing code, the check for IndicesTheSame is followed by:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nSo, to make this safe, we need to add a condition that both GEPs have no-wrap flags that prevent the offset from affecting the comparison. Since the GEPs have the same indices, the offset added is the same. However, if the addition could wrap for either GEP, then comparing the bases directly isn't valid.\n\nThus, the code should only perform this fold if both GEPs are inbounds or have both nuw and nsw flags. Wait, but inbounds implies certain no-wrap guarantees. Wait, inbounds GEPs have the property that the resulting pointer is either in the same object or one past the end. But comparing pointers from different objects is undefined unless they are based on the same object. So, the original code's transformation is only valid if the pointers are within the same object, which the compiler can't assume.\n\nTherefore, the fold is only valid if the offset is zero, but that's not the case here. Wait, the indices are the same but non-zero. So, the transformation is incorrect unless the offset addition doesn't affect the comparison. This can only be guaranteed if the offset is zero (no change) or if the pointers are based on the same object and the offset is such that the order is preserved. However, since the base pointers are different, the compiler can't assume they are in the same object.\n\nTherefore, the fold is invalid unless certain flags are present that prevent the offset from affecting the comparison. The necessary flags would be that both GEPs have no-wrap flags (nuw and nsw) such that adding the same offset to both bases doesn't change their order.\n\nSo, to fix the bug, in the code where the fold is performed (the line returning the new ICmpInst), we need to check that both GEPLHS and GEPRHS have the necessary flags. For example, both have nuw and nsw. Alternatively, perhaps the GEPs must be inbounds, but in the test case, they are not. Wait, the test case has GEPs with nuw and nusw, but the original code's example is:\n\ndefine i1 @test(ptr %x, ptr %y) {\n %gep1 = getelementptr i8, ptr %x, i32 1\n %gep2 = getelementptr i8, ptr %y, i32 1\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n\nThe Alive2 example shows that if %x is a pointer near the end of the address space, adding 1 wraps to null, while %y is null. Then, %gep1 is null (due to wrap), and %gep2 is 1. So, the comparison is 0 < 1 (true), but the transformed code compares %x < %y. If %x is -1 (assuming 0xffff...) and %y is 0, then the transformed code compares -1 < 0 (which in unsigned is 0xffff... < 0, which is false). Thus, the result is inverted.\n\nThus, the fold is invalid unless the addition does not wrap. So, the GEPs must have nuw and nsw (or inbounds) flags that prevent wrapping. Wait, inbounds GEPs have the property that the resulting pointer is within the allocated object or one past. But if the base pointers are different, this doesn't help. So, the only way to ensure that adding the same offset to two different base pointers doesn't change their order is if the offset is such that the addition doesn't wrap for either pointer. Thus, the GEPs must have both nuw and nsw flags.\n\nSo, the fix is to check that both GEPLHS and GEPRHS have both nuw and nsw flags. However, in LLVM, GEPs can have nuw (no unsigned wrap) and nsw (no signed wrap) flags. For pointers, the nsw flag is not applicable in the same way as integers. Wait, but in LLVM, the nusw (no unsigned signed wrap?) isn't a thing. Wait, the flags for GEP are actually \"inbounds\", \"nuw\", and \"nsw\". Wait, for GEP, the flags are:\n\n- inbounds: the resulting pointer is within the bounds of the object.\n- nuw: the GEP is using unsigned arithmetic and doesn't wrap.\n- nsw: the GEP is using signed arithmetic and doesn't wrap.\n\nBut for pointers, how do these flags apply? The documentation says that nuw and nsw are for the integer addition of the offset. So, if a GEP has nuw, then the offset added to the base (as an integer) doesn't wrap in unsigned arithmetic. Similarly for nsw.\n\nThus, if both GEPs have nuw, then adding the offset to both bases (as integers) won't wrap in the unsigned sense. Similarly for nsw. So, for the comparison to be valid, the GEPs must have flags that ensure that the addition does not wrap in the direction that would affect the comparison.\n\nFor the example, the problem occurs when one GEP's addition wraps (like when adding 1 to 0xffff... results in 0), but the other doesn't. If both GEPs have nuw, then this wrap can't happen. So, the fold is safe if both GEPs have nuw, because adding the same offset to both bases (as integers) won't wrap, so the comparison of the bases is equivalent to the comparison of the GEPs.\n\nSimilarly, if the comparison is signed, then maybe nsw is required. But in the test case, the comparison is unsigned (ult). So, if the GEPs have nuw flags, then the unsigned addition doesn't wrap, and comparing the GEPs is the same as comparing the bases plus the offset (but since the offset is the same, it's equivalent to comparing the bases).\n\nWait, if both GEPs add the same offset, and both have nuw, then the base1 + offset < base2 + offset (as unsigned) is equivalent to base1 < base2, because adding the same offset (without wrapping) preserves the order.\n\nTherefore, the fold is safe if both GEPs have nuw and the comparison is unsigned. For signed comparisons, it would require nsw.\n\nBut in the existing code, the condition is only checking if the indices are the same. To fix the bug, we need to add a check that both GEPs have the appropriate no-wrap flags for the comparison predicate.\n\nIn the code, when we have:\n\nif (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nWe need to add a condition that the GEPs' no-wrap flags ensure that the addition doesn't affect the comparison. For this, we need to check that both GEPs have nuw if the comparison is unsigned, and nsw if the comparison is signed.\n\nWait, but the predicate could be any. So, for example, if the comparison is ult (unsigned), then we need to ensure that the GEPs' additions don't wrap in the unsigned sense (nuw). If the comparison is slt (signed), then we need nsw.\n\nBut this complicates the condition. Alternatively, require that both GEPs have both nuw and nsw flags, ensuring that the addition doesn't wrap in either sense. But that might be too restrictive.\n\nAlternatively, check that the GEPs have the appropriate no-wrap flags based on the comparison predicate.\n\nFor example, if the comparison is unsigned (ult/ule/ugt/uge), then require that both GEPs have nuw.\n\nIf the comparison is signed (slt/sle/sgt/sge), require that both GEPs have nsw.\n\nFor equality comparisons (eq/ne), the flags don't matter because the offset is the same, so the GEPs would be equal iff the bases are equal, regardless of wrapping. But wait, that's not true. For example, if base1 is 0xffffffff and base2 is 0x0, adding 1 (with wrapping) would make them both 0x0, so their GEPs would be equal, but the bases are not. So, for equality comparisons, the fold is only valid if the addition doesn't wrap for either GEP, so that the equality is preserved.\n\nSo, in the code, when replacing the GEP comparison with a base comparison, the code must ensure that the no-wrap flags on the GEPs guarantee that the offset addition does not wrap for the purpose of the comparison.\n\nIn the existing code, this check is missing, leading to incorrect folds.\n\nSo, the fix is to modify the condition where the code returns the new ICmpInst to include a check that both GEPs have the necessary no-wrap flags based on the predicate.\n\nFor example, for an unsigned comparison (Cond is ult, ule, ugt, uge), require that both GEPs have the nuw flag. For a signed comparison, require nsw. For equality, require that both GEPs have either nuw or nsw, but perhaps even that is not sufficient. Wait, for equality, if the GEPs wrap in different ways, they could end up equal even if the bases are different. For example, base1 = 0xffffffff, base2 = 0x0, offset 1. Then GEP1 is 0x0, GEP2 is 0x1. So they are not equal. But if base1 is 0xfffffffe and base2 is 0x0, offset 2. Then GEP1 is 0x0 (if wrapping), GEP2 is 0x2. So, not equal. But perhaps when the offset is the same, the GEPs can't become equal unless the bases are equal or the addition wraps. So, for equality comparisons, the fold is only safe if the addition doesn't wrap, so the GEPs are equal if and only if the bases are equal. Thus, for equality, the fold is valid if the GEPs have either nuw or nsw, but perhaps even inbounds?\n\nWait, but in the Alive2 example, the equality comparison is not involved. The example uses ult. But the code is handling equality comparisons elsewhere. Let's look back at the code.\n\nThe code snippet includes a part where for equality conditions and inbounds GEPs, it does some handling. But the problematic code is in the part where the GEPs have different base pointers but same indices. The existing code doesn't check the no-wrap flags here, leading to incorrect folds.\n\nThus, the solution is to add a check in the code where the indices are the same. So, modify the condition to check that both GEPs have the necessary no-wrap flags for the comparison predicate.\n\nThe code currently has:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nWe need to adjust this to only perform the fold if the GEPs have the required no-wrap flags.\n\nFor example, adding:\n\n if (IndicesTheSame && \n GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap() &&\n CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nBut wait, this would only allow the fold if both GEPs have nuw. However, if the comparison is signed (slt, etc.), then we need nsw. So the check depends on the predicate.\n\nBut the code here is handling any condition (Cond). So, how do we check the flags based on the predicate?\n\nAlternatively, we can check that the GEPs have both nuw and nsw flags, ensuring that the addition doesn't wrap in any case. But that might be too restrictive.\n\nAlternatively, check that the GEPs have nuw if the comparison is unsigned, or nsw if the comparison is signed. For equality, perhaps require nuw or nsw.\n\nBut how to implement this in the code?\n\nThe code currently has the ICmpInst::Predicate Cond. So, for each condition, we need to determine which flags are required.\n\nFor example:\n\n- For unsigned comparisons (ult, ule, ugt, uge), require that both GEPs have nuw.\n- For signed comparisons (slt, sle, sgt, sge), require that both GEPs have nsw.\n- For equality/inequality (eq, ne), require that both GEPs have either nuw or nsw (but this may not be sufficient).\n\nBut this is complicated. Alternatively, only allow the fold if both GEPs have nuw, and the comparison is unsigned, or both have nsw and the comparison is signed. For equality, maybe allow if either is present.\n\nBut how to handle this in code?\n\nAlternatively, the fold is only valid if the GEPs have nuw for any comparison, as the nuw ensures that the offset addition doesn't affect the unsigned comparison. But that may not be the case.\n\nAlternatively, the fold is only valid if the GEPs have no-wrap flags (either nuw or nsw) that correspond to the comparison's signedness.\n\nBut this requires more analysis.\n\nAlternatively, the correct approach is to check that the GEPs' offsets can be subtracted from both sides of the comparison. For example, if GEPLHS = base1 + offset, GEPRHS = base2 + offset, then comparing GEPLHS < GEPRHS is equivalent to comparing base1 < base2, provided that adding offset to both doesn't wrap. So, if both additions are nuw, then for the unsigned comparison, the equivalence holds. Similarly, if both are nsw, then for signed comparisons.\n\nThus, in code, we can check:\n\nif (IndicesTheSame) {\n bool CanFold = false;\n if (ICmpInst::isUnsigned(Cond))\n CanFold = GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap();\n else if (ICmpInst::isSigned(Cond))\n CanFold = GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap();\n else // equality\n CanFold = (GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap()) ||\n (GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap());\n if (CanFold && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n}\n\nBut in the code snippet provided, the code checks:\n\n if (IndicesTheSame)\n for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i)\n if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {\n IndicesTheSame = false;\n break;\n }\n\n // If all indices are the same, just compare the base pointers.\n Type *BaseType = GEPLHS->getOperand(0)->getType();\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nSo, adding the CanFold condition here would address the problem.\n\nThus, modifying the code to include checks on the GEPs' no-wrap flags based on the predicate.\n\nIn the existing code, the line is:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nWe need to modify this to:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType()) {\n bool CanFold = false;\n if (ICmpInst::isUnsigned(Cond)) {\n CanFold = GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap();\n } else if (ICmpInst::isSigned(Cond)) {\n CanFold = GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap();\n } else {\n // For equality, ensure that neither GEP wraps. Since for equality,\n // the result is equivalent only if adding the same offset to both\n // bases doesn't wrap for either, hence the GEPs must have both nuw and nsw?\n // Or maybe either nuw or nsw is sufficient? Not sure.\n // Alternatively, for equality, it's only safe if both GEPs have either nuw or nsw.\n // But this is tricky. Maybe for equality, we can't fold unless both have nuw and nsw.\n CanFold = (GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap()) ||\n (GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap());\n }\n if (CanFold) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n }\n }\n\nBut this might not be correct for equality. For example, if both GEPs have nsw, but the comparison is equality, then adding the same offset (which doesn't signed wrap) would mean that the GEPs are equal iff the bases are equal. Similarly for nuw.\n\nBut in the case where the GEPs have different flags, like one has nuw and the other has nsw, then this check would fail. For equality, perhaps we need to require that both GEPs have the same kind of no-wrap flags. Alternatively, for equality, it's sufficient if either both have nuw or both have nsw. Or even if one has nuw and the other has nsw.\n\nBut this requires further analysis.\n\nAlternatively, for equality, the fold is only valid if the GEPs have both nuw and nsw. Because, if the addition could wrap in any way, then the equality of the GEPs doesn't imply equality of the bases.\n\nFor example, if base1 is 0xffffffff (assuming 32-bit), and base2 is 0x00000000, and we add 1 with nuw. Then, GEP1 would wrap to 0, GEP2 would be 0x00000001. So, they are not equal. But if base2 is 0x00000000, and the offset is 1, then GEP2 is 0x00000001. So, in this case, the GEPs are not equal. But if base1 is 0xfffffffe and base2 is 0x00000000, offset 2: GEP1 would wrap to 0x00000000 (with nuw), and GEP2 would be 0x00000002. So, not equal. Thus, for equality comparisons, as long as the GEPs have nuw, the fold is safe. Similarly, if they have nsw.\n\nBut if the GEPs have no flags, then it's possible that adding the same offset could make two different bases equal. For example, base1 = 0xffffffff (as a pointer), base2 = 0x00000000, offset 1. Then, GEP1 is 0x00000000 (assuming 32-bit), GEP2 is 0x00000001. So, they are not equal. Wait, but in this case, the bases are different, and the offset is the same. The GEPs would only be equal if base1 + offset == base2 + offset, which is equivalent to base1 == base2. But if the addition wraps, this is not necessarily the case. For example, base1 = 0xffffffff, offset 1 (nuw). Then, the addition wraps, but the nuw flag is not present. So, in this case, without nuw, the wrap is allowed, and the GEP1 becomes 0x00000000. So, if base2 is 0x00000000, then GEP2 would be 0x00000001. So, the GEPs are not equal. Therefore, even without no-wrap flags, the equality of GEPs implies equality of the bases. Wait, is that true?\n\nWait, if base1 != base2, but base1 + offset == base2 + offset (modulo 2^n), then GEPs would compare equal even if bases are different. For example, base1 = 1, base2 = 2^32 - 1 (assuming 32-bit pointers), offset = 1. Then, base1 + 1 = 2, base2 + 1 = 0 (if no nuw), so GEPs are 2 and 0, which are not equal. So, in that case, bases are different, GEPs are also different.\n\nAnother example: base1 = 2^31 -1, base2 = - (2^31) (signed integers), offset = 1. Then, base1 +1 = 2^31 (signed overflow if considered as 32-bit), but in unsigned terms, it's 0x80000000. base2 +1 is - (2^31 -1). If we have a signed comparison, but the GEPs are treated as pointers (unsigned), then their unsigned values are different. So, the GEPs would not be equal.\n\nSo, perhaps for equality comparisons, the fold is always valid. Because even if the offset addition wraps, the GEPs will only be equal if the bases are equal. But wait, suppose base1 = 0xffffffff, base2 = 0x00000000, offset = 0. Then, GEPs are the same as the bases, so they are not equal. If the offset is 1, then GEP1 is 0x00000000 (if no nuw), GEP2 is 0x00000001. Still not equal. So, for equality comparisons, the fold (comparing the bases) is valid regardless of no-wrap flags. Because the offset is the same for both GEPs, so the GEPs can only be equal if the bases are equal. Because even with wrapping, adding the same offset to two different bases will not make them equal unless the bases are equal. Because base1 + offset \u2261 base2 + offset (mod 2^N) implies base1 \u2261 base2 (mod 2^N), which is only possible if base1 == base2 as pointers. Because pointers are treated as integers, but address spaces may vary. But in the same address space, two different base pointers adding the same offset cannot result in the same pointer unless the bases are the same. Because base1 + offset == base2 + offset => base1 == base2.\n\nWait, no. If offset is added as an integer, then base1 + offset == base2 + offset (mod 2^N) implies base1 == base2 (mod 2^N), which for pointers would imply that the bases are the same, since pointers are just integers in this context. But if base1 and base2 are different pointers (different addresses), then adding the same offset to each would result in different addresses unless they are the same base. So, the GEPs can only be equal if the bases are equal. Therefore, for equality comparisons, comparing the GEPs is equivalent to comparing the bases, regardless of no-wrap flags. Because even if the addition wraps, the same offset added to different bases cannot result in the same pointer.\n\nWait, but that's not correct. For example, base1 is 0xffffffff and base2 is 0x00000000. Adding offset 1 would result in 0x00000000 and 0x00000001. Not equal. But if base1 is 0xfffffffe and offset 2, then 0xfffffffe + 2 = 0x00000000 (assuming 32-bit, no nuw), and base2 is 0xffffffff with offset 1: 0xffffffff +1 = 0x00000000. Then, the GEPs would be equal (both 0x00000000) but the bases are different. Ah, this is a case where base1 + offset1 equals base2 + offset2. But in our scenario, the offsets are the same for both GEPs. So, if base1 and base2 are different, and offsets are the same, then base1 + offset can only equal base2 + offset if base1 == base2. Because base1 + offset = base2 + offset => base1 = base2. So, even with wrapping, the equality of the GEPs implies equality of the bases. Therefore, for equality comparisons, the fold is always valid, regardless of no-wrap flags.\n\nThus, for equality comparisons (eq/ne), the code can safely fold the GEP comparison to a base comparison, even without any no-wrap flags. Because the same offset added to different bases cannot make the pointers equal unless the bases are equal.\n\nTherefore, the fix is to modify the code to only require the no-wrap flags for relational comparisons (ult, ule, ugt, uge, slt, etc.), but for equality, it's safe to fold regardless.\n\nThus, in code, we can adjust the condition to:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType()) {\n if (ICmpInst::isEquality(Cond)) {\n // For equality, folding is safe because adding the same offset to\n // different bases cannot make them equal.\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n } else {\n // For relational comparisons, require that both GEPs have the appropriate no-wrap flags.\n bool CanFold = false;\n if (ICmpInst::isUnsigned(Cond)) {\n CanFold = GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap();\n } else if (ICmpInst::isSigned(Cond)) {\n CanFold = GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap();\n }\n if (CanFold) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n }\n }\n }\n\nBut in the existing code, the check is:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nSo, modifying this to check for the no-wrap flags only for relational comparisons.\n\nThus, the code becomes:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType()) {\n if (ICmpInst::isEquality(Cond)) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n } else if ((ICmpInst::isUnsigned(Cond) &&\n GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap()) ||\n (ICmpInst::isSigned(Cond) &&\n GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap())) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n }\n }\n\nThis way, for equality comparisons, the fold is performed unconditionally, while for relational comparisons, it's only done if the appropriate no-wrap flags are present.\n\nIn the test case provided, the comparison is ult (unsigned), and the GEPs have different flags (nuw and nusw). So, GEPLHS has nuw, GEPRHS has nsw. The code's check for unsigned comparison would require both GEPs to have nuw. Since GEPRHS does not have nuw (only nsw), the fold is not performed, preventing the incorrect transformation.\n\nTherefore, this change would fix the bug.\n\nNow, let's look at the code snippet provided in the problem. The code in question is:\n\n for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i)\n if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {\n IndicesTheSame = false;\n break;\n }\n\n // If all indices are the same, just compare the base pointers.\n Type *BaseType = GEPLHS->getOperand(0)->getType();\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nWe need to modify the code after checking IndicesTheSame to include the conditions based on the predicate and flags.\n\nSo, the modified code would look like:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType()) {\n if (ICmpInst::isEquality(Cond)) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n } else if (ICmpInst::isUnsigned(Cond) &&\n GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap()) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n } else if (ICmpInst::isSigned(Cond) &&\n GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap()) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n }\n }\n\nThus, in the code snippet provided in the problem, the line:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType())\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n\nShould be replaced with:\n\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType()) {\n if (ICmpInst::isEquality(Cond)) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n } else if (ICmpInst::isUnsigned(Cond) &&\n GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap()) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n } else if (ICmpInst::isSigned(Cond) &&\n GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap()) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n }\n }\n\nThis ensures that for equality comparisons, the fold is done, and for relational comparisons, only when the appropriate no-wrap flags are present.\n\nThus, the corrected code for the specified section would include the checks for hasNoUnsignedWrap and hasNoSignedWrap based on the predicate."
47
- },
48
- {
49
- "role": "user",
50
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (5.9s)\n-- Generating done (3.2s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/87] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/87] Linking CXX executable bin/llvm-config\n[3/87] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp: In member function \u2018llvm::Instruction* llvm::InstCombinerImpl::foldGEPICmp(llvm::GEPOperator*, llvm::Value*, llvm::CmpPredicate, llvm::Instruction&)\u2019:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:775:28: error: \u2018class llvm::GEPOperator\u2019 has no member named \u2018hasNoSignedWrap\u2019; did you mean \u2018hasNoUnsignedWrap\u2019?\n 775 | GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap()) {\n | ^~~~~~~~~~~~~~~\n | hasNoUnsignedWrap\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:775:57: error: \u2018class llvm::GEPOperator\u2019 has no member named \u2018hasNoSignedWrap\u2019; did you mean \u2018hasNoUnsignedWrap\u2019?\n 775 | GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap()) {\n | ^~~~~~~~~~~~~~~\n | hasNoUnsignedWrap\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:818:45: error: \u2018class llvm::GEPOperator\u2019 has no member named \u2018getNumOperandss\u2019; did you mean \u2018getNumOperands\u2019?\n 818 | if (GEPLHS->getNumOperands() == GEPRHS->getNumOperandss() &&\n | ^~~~~~~~~~~~~~~\n | getNumOperands\nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback.\nPlease answer with the code directly. Do not include any additional information in the output.\nPlease answer with the complete code snippet (including the unmodified part) that replaces the original code. Do not answer with a diff.\nPlease make sure the answer includes the prefix:\n```cpp\n Constant::getNullValue(Offset->getType()));\n }\n\n if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&\n isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&\n```\nand the suffix:\n```cpp\n Value *LHSV = GEPLHS->getOperand(DiffOperand);\n Value *RHSV = GEPRHS->getOperand(DiffOperand);\n return NewICmp(NW, LHSV, RHSV);\n }\n }\n```\n"
51
- },
52
- {
53
- "role": "assistant",
54
- "content": "```cpp\n Constant::getNullValue(Offset->getType()));\n }\n\n if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&\n isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&\n !NullPointerIsDefined(I.getFunction(),\n RHS->getType()->getPointerAddressSpace())) {\n // For most address spaces, an allocation can't be placed at null, but null\n // itself is treated as a 0 size allocation in the in bounds rules. Thus,\n // the only valid inbounds address derived from null, is null itself.\n // Thus, we have four cases to consider:\n // 1) Base == nullptr, Offset == 0 -> inbounds, null\n // 2) Base == nullptr, Offset != 0 -> poison as the result is out of bounds\n // 3) Base != nullptr, Offset == (-base) -> poison (crossing allocations)\n // 4) Base != nullptr, Offset != (-base) -> nonnull (and possibly poison)\n //\n // (Note if we're indexing a type of size 0, that simply collapses into one\n // of the buckets above.)\n //\n // In general, we're allowed to make values less poison (i.e. remove\n // sources of full UB), so in this case, we just select between the two\n // non-poison cases (1 and 4 above).\n //\n // For vectors, we apply the same reasoning on a per-lane basis.\n auto *Base = GEPLHS->getPointerOperand();\n if (GEPLHS->getType()->isVectorTy() && Base->getType()->isPointerTy()) {\n auto EC = cast<VectorType>(GEPLHS->getType())->getElementCount();\n Base = Builder.CreateVectorSplat(EC, Base);\n }\n return new ICmpInst(Cond, Base,\n ConstantExpr::getPointerBitCastOrAddrSpaceCast(\n cast<Constant>(RHS), Base->getType()));\n } else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {\n // If the base pointers are different, but the indices are the same, just\n // compare the base pointer.\n if (PtrBase != GEPRHS->getOperand(0)) {\n bool IndicesTheSame =\n GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&\n GEPLHS->getPointerOperand()->getType() ==\n GEPRHS->getPointerOperand()->getType() &&\n GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType();\n if (IndicesTheSame)\n for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i)\n if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {\n IndicesTheSame = false;\n break;\n }\n\n // If all indices are the same, just compare the base pointers.\n Type *BaseType = GEPLHS->getOperand(0)->getType();\n if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType()) {\n if (ICmpInst::isEquality(Cond)) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n } else if (ICmpInst::isUnsigned(Cond) &&\n GEPLHS->hasNoUnsignedWrap() && GEPRHS->hasNoUnsignedWrap()) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n } else if (ICmpInst::isSigned(Cond) &&\n (GEPLHS->getNoWrapFlags() & GEPNoWrapFlags::NSW) &&\n (GEPRHS->getNoWrapFlags() & GEPNoWrapFlags::NSW)) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n }\n }\n\n // If we're comparing GEPs with two base pointers that only differ in type\n // and both GEPs have only constant indices or just one use, then fold\n // the compare with the adjusted indices.\n // FIXME: Support vector of pointers.\n if (GEPLHS->isInBounds() && GEPRHS->isInBounds() &&\n (GEPLHS->hasAllConstantIndices() || GEPLHS->hasOneUse()) &&\n (GEPRHS->hasAllConstantIndices() || GEPRHS->hasOneUse()) &&\n PtrBase->stripPointerCasts() ==\n GEPRHS->getOperand(0)->stripPointerCasts() &&\n !GEPLHS->getType()->isVectorTy()) {\n Value *LOffset = EmitGEPOffset(GEPLHS);\n Value *ROffset = EmitGEPOffset(GEPRHS);\n\n // If we looked through an addrspacecast between different sized address\n // spaces, the LHS and RHS pointers are different sized\n // integers. Truncate to the smaller one.\n Type *LHSIndexTy = LOffset->getType();\n Type *RHSIndexTy = ROffset->getType();\n if (LHSIndexTy != RHSIndexTy) {\n if (LHSIndexTy->getPrimitiveSizeInBits().getFixedValue() <\n RHSIndexTy->getPrimitiveSizeInBits().getFixedValue()) {\n ROffset = Builder.CreateTrunc(ROffset, LHSIndexTy);\n } else\n LOffset = Builder.CreateTrunc(LOffset, RHSIndexTy);\n }\n\n Value *Cmp = Builder.CreateICmp(ICmpInst::getSignedPredicate(Cond),\n LOffset, ROffset);\n return replaceInstUsesWith(I, Cmp);\n }\n\n // Otherwise, the base pointers are different and the indices are\n // different. Try convert this to an indexed compare by looking through\n // PHIs/casts.\n return transformToIndexedCompare(GEPLHS, RHS, Cond, DL, *this);\n }\n\n GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags() & GEPRHS->getNoWrapFlags();\n if (GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&\n GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType()) {\n // If the GEPs only differ by one index, compare it.\n unsigned NumDifferences = 0; // Keep track of # differences.\n unsigned DiffOperand = 0; // The operand that differs.\n for (unsigned i = 1, e = GEPRHS->getNumOperands(); i != e; ++i)\n if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {\n Type *LHSType = GEPLHS->getOperand(i)->getType();\n Type *RHSType = GEPRHS->getOperand(i)->getType();\n // FIXME: Better support for vector of pointers.\n if (LHSType->getPrimitiveSizeInBits() !=\n RHSType->getPrimitiveSizeInBits() ||\n (GEPLHS->getType()->isVectorTy() &&\n (!LHSType->isVectorTy() || !RHSType->isVectorTy()))) {\n // Irreconcilable differences.\n NumDifferences = 2;\n break;\n }\n\n if (NumDifferences++) break;\n DiffOperand = i;\n }\n\n if (NumDifferences == 0) // SAME GEP?\n return replaceInstUsesWith(I, // No comparison is needed here.\n ConstantInt::get(I.getType(), ICmpInst::isTrueWhenEqual(Cond)));\n\n else if (NumDifferences == 1 && CanFold(NW)) {\n Value *LHSV = GEPLHS->getOperand(DiffOperand);\n Value *RHSV = GEPRHS->getOperand(DiffOperand);\n return NewICmp(NW, LHSV, RHSV);\n }\n }\n```",
55
- "reasoning_content": "Okay, I need to fix the compilation errors in the provided code. Let me look at the error messages again.\n\nFirst error: 'hasNoSignedWrap' is not a member of 'GEPOperator'. Oh right, GEPOperator uses 'hasNoSignedWrap()'? Wait, no, maybe I confused it. Let me check LLVM's documentation. Oh, right, GEPOperator has methods like hasNoSignedWrap() and hasNoUnsignedWrap(). Wait, the error says the code is using 'hasNoSignedWrap' but the compiler says it's not a member. Wait, maybe the correct method is 'hasNoSignedOverflow()' or something else. Wait, no, in LLVM's GEPOperator, the methods are hasNoSignedWrap() and hasNoUnsignedWrap(). Wait, but maybe in the version being used here, those methods aren't present. Wait, the error message suggests 'hasNoUnsignedWrap' as a possible alternative. Hmm, maybe the code was mistakenly using 'hasNoSignedWrap' when it should be 'hasNoUnsignedWrap'? Or perhaps there's a typo.\n\nLooking at the code, the line in question is:\n\nelse if (ICmpInst::isSigned(Cond) &&\n GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap()) {\n\nBut the error says 'hasNoSignedWrap' is not a member. So maybe the correct method is 'hasNoSignedOverflow()' or another name. Wait, checking LLVM's source code for GEPOperator. Oh, right! The GEPOperator class has methods like getNoWrapFlags(), which returns a GEPNoWrapFlags enum. To check for no signed wrap, you use hasNoSignedWrap(), but maybe in the version this code is targeting, that method isn't available. Wait, but the user's code was modified earlier, perhaps there was a typo. Alternatively, perhaps the code should check for the presence of the 'nsw' flag.\n\nWait, the original code had a check for NW (no wrap flags), and in the modified code, the user added conditions checking if both GEPLHS and GEPRHS have no signed wrap. But the error indicates that 'hasNoSignedWrap' is not a member. Maybe the correct method is 'hasNoUnsignedWrap'? But that doesn't make sense for a signed comparison. Alternatively, perhaps the code should check the no wrap flags using getNoWrapFlags().\n\nWait, looking at the LLVM documentation, GEPOperator has a method hasNoSignedWrap() which returns true if the NSW flag is set. Similarly for NUW. So if the code is using hasNoSignedWrap(), that should be correct. But the error says the compiler can't find that method. So maybe there's a typo in the code. Let me check the code again.\n\nLooking at the code snippet:\n\n} else if (ICmpInst::isSigned(Cond) &&\n GEPLHS->hasNoSignedWrap() && GEPRHS->hasNoSignedWrap()) {\n return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));\n}\n\nThe error is that 'hasNoSignedWrap' is not a member. So maybe in the actual code, the method is named differently. Wait, perhaps the correct method is hasNoSignedOverflow()? Or maybe the code is using the wrong method. Alternatively, perhaps the code should be checking the no wrap flags via the GEPNoWrapFlags.\n\nWait, GEPOperator has a method getNoWrapFlags() which returns a GEPNoWrapFlags. Then, to check for NSW, you would use (getNoWrapFlags() & GEPNoWrapFlags::NSW) != 0. So maybe the code should be written as:\n\nGEPLHS->getNoWrapFlags() & GEPNoWrapFlags::NSW\n\nSimilarly for RHS. But in the code, the user tried to call hasNoSignedWrap(), which might not exist. So that's the error. Therefore, the code should check if the NSW flag is set using getNoWrapFlags().\n\nSo, replacing GEPLHS->hasNoSignedWrap() with (GEPLHS->getNoWrapFlags() & GEPNoWrapFlags::NSW) != 0.\n\nSimilarly for GEPRHS.\n\nSo the line would become:\n\n} else if (ICmpInst::isSigned(Cond) &&\n (GEPLHS->getNoWrapFlags() & GEPNoWrapFlags::NSW) &&\n (GEPRHS->getNoWrapFlags() & GEPNoWrapFlags::NSW)) {\n\nThat would correctly check if both GEPs have the NSW flag set.\n\nNext error: 'getNumOperandss' is not a member. That's a typo. The code has GEPRHS->getNumOperandss() instead of getNumOperands(). So the correct line should be:\n\nif (GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&\n\nSo that's a simple typo where an extra 's' was added to 'getNumOperands'.\n\nSo, fixing that typo.\n\nPutting it all together, the modified code should replace the hasNoSignedWrap() checks with checks on the NSW flag using getNoWrapFlags(), and fix the typo in getNumOperands()."
56
- },
57
- {
58
- "role": "user",
59
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (10.8s)\n-- Generating done (6.0s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/87] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/87] Linking CXX executable bin/llvm-config\n[3/87] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp: In member function \u2018llvm::Instruction* llvm::InstCombinerImpl::foldGEPICmp(llvm::GEPOperator*, llvm::Value*, llvm::CmpPredicate, llvm::Instruction&)\u2019:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:775:64: error: \u2018NSW\u2019 is not a member of \u2018llvm::GEPNoWrapFlags\u2019\n 775 | (GEPLHS->getNoWrapFlags() & GEPNoWrapFlags::NSW) &&\n | ^~~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:776:64: error: \u2018NSW\u2019 is not a member of \u2018llvm::GEPNoWrapFlags\u2019\n 776 | (GEPRHS->getNoWrapFlags() & GEPNoWrapFlags::NSW)) {\n | ^~~\nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback.\nPlease answer with the code directly. Do not include any additional information in the output.\nPlease answer with the complete code snippet (including the unmodified part) that replaces the original code. Do not answer with a diff.\nPlease make sure the answer includes the prefix:\n```cpp\n Constant::getNullValue(Offset->getType()));\n }\n\n if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&\n isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&\n```\nand the suffix:\n```cpp\n Value *LHSV = GEPLHS->getOperand(DiffOperand);\n Value *RHSV = GEPRHS->getOperand(DiffOperand);\n return NewICmp(NW, LHSV, RHSV);\n }\n }\n```\n"
60
- },
61
- {
62
- "role": "assistant",
63
- "content": ""
64
- },
65
- {
66
- "role": "user",
67
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (5.9s)\n-- Generating done (3.2s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/87] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/87] Linking CXX executable bin/llvm-config\n[3/87] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp: In member function \u2018llvm::Instruction* llvm::InstCombinerImpl::foldGEPICmp(llvm::GEPOperator*, llvm::Value*, llvm::CmpPredicate, llvm::Instruction&)\u2019:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:719:5: error: expected primary-expression before \u2018if\u2019\n 719 | if (CanFold(NW)) {\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:724:6: error: expected \u2018;\u2019 before \u2018}\u2019 token\n 724 | }\n | ^\n | ;\n 725 | }\n | ~ \nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback.\nPlease answer with the code directly. Do not include any additional information in the output.\nPlease answer with the complete code snippet (including the unmodified part) that replaces the original code. Do not answer with a diff.\nPlease make sure the answer includes the prefix:\n```cpp\n Constant::getNullValue(Offset->getType()));\n }\n\n if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&\n isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&\n```\nand the suffix:\n```cpp\n Value *LHSV = GEPLHS->getOperand(DiffOperand);\n Value *RHSV = GEPRHS->getOperand(DiffOperand);\n return NewICmp(NW, LHSV, RHSV);\n }\n }\n```\n"
68
- },
69
- {
70
- "role": "assistant",
71
- "content": ""
72
- },
73
- {
74
- "role": "user",
75
- "content": "Feedback:\nCMake Deprecation Warning at /data/zyw/llvm-apr-benchmark/work/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):\n The OLD behavior for policy CMP0116 will be removed from a future version\n of CMake.\n\n The cmake-policies(7) manual explains that the OLD behaviors of all\n policies are deprecated and that a policy should be set to OLD only under\n specific short-term circumstances. Projects should be ported to the NEW\n behavior and not rely on setting a policy to OLD.\nCall Stack (most recent call first):\n CMakeLists.txt:8 (include)\n\n\n-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) \n-- LLVM host triple: x86_64-unknown-linux-gnu\n-- Native target architecture is X86\n-- Threads enabled.\n-- Doxygen disabled.\n-- Ninja version: 1.10.0\n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) \n-- OCaml bindings disabled.\n-- LLVM default target triple: x86_64-unknown-linux-gnu\n-- Building with -fPIC\n-- Targeting X86\n-- Targeting RISCV\n-- Targeting AArch64\n-- Targeting SystemZ\n-- Targeting Hexagon\n-- Failed to find LLVM FileCheck\n-- Google Benchmark version: v0.0.0, normalized to 0.0.0\n-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile\n-- Performing Test HAVE_POSIX_REGEX -- success\n-- Performing Test HAVE_STEADY_CLOCK -- success\n-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile\n-- Configuring done (8.5s)\n-- Generating done (4.7s)\n-- Build files have been written to: /data/zyw/llvm-apr-benchmark/work/llvm-build\n\n[1/87] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o\n[2/87] Linking CXX executable bin/llvm-config\n[3/87] Building CXX object lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o\nFAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o \nccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/data/zyw/llvm-apr-benchmark/work/llvm-build/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine -I/data/zyw/llvm-apr-benchmark/work/llvm-build/include -I/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstCombineCompares.cpp.o -c /data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp: In member function \u2018llvm::Instruction* llvm::InstCombinerImpl::foldGEPICmp(llvm::GEPOperator*, llvm::Value*, llvm::CmpPredicate, llvm::Instruction&)\u2019:\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:719:5: error: expected primary-expression before \u2018if\u2019\n 719 | if (CanFold(NW)) {\n | ^~\n/data/zyw/llvm-apr-benchmark/work/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:724:6: error: expected \u2018;\u2019 before \u2018}\u2019 token\n 724 | }\n | ^\n | ;\n 725 | }\n | ~ \nninja: build stopped: subcommand failed.\n\nPlease adjust code according to the feedback.\nPlease answer with the code directly. Do not include any additional information in the output.\nPlease answer with the complete code snippet (including the unmodified part) that replaces the original code. Do not answer with a diff.\nPlease make sure the answer includes the prefix:\n```cpp\n Constant::getNullValue(Offset->getType()));\n }\n\n if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&\n isa<Constant>(RHS) && cast<Constant>(RHS)->isNullValue() &&\n```\nand the suffix:\n```cpp\n Value *LHSV = GEPLHS->getOperand(DiffOperand);\n Value *RHSV = GEPRHS->getOperand(DiffOperand);\n return NewICmp(NW, LHSV, RHSV);\n }\n }\n```\n"
76
- }
77
- ]
78
- }
79
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
examples/fixes/121584.json DELETED
The diff for this file is too large to render. See raw diff
 
examples/fixes/122584.json DELETED
The diff for this file is too large to render. See raw diff
 
scripts/extract_from_issues.py CHANGED
@@ -34,7 +34,7 @@ session.headers.update(
34
  )
35
 
36
  issue_id_begin = 76663 # Since 2024-01-01
37
- issue_id_end = 126174
38
 
39
 
40
  def wait(progress):
 
34
  )
35
 
36
  issue_id_begin = 76663 # Since 2024-01-01
37
+ issue_id_end = 126720
38
 
39
 
40
  def wait(progress):